易截截图软件、单文件、免安装、纯绿色、仅160KB

c版本与c++版本的动态数组代码

C版本:
vim stash.h
#ifndef STASH_H
#define STASH_H
typedef struct STASHTag {
  int size;  /* Size of each space */
  int quantity; /* Number of storage spaces */
  int next; /* Next empty space */
  /* Dynamically allocated array of bytes: */
  unsigned char* storage;
} Stash;
void initialize(Stash* S, int Size);
void cleanup(Stash* S);
int add(Stash* S, void* element);
void* fetch(Stash* S, int index);
int count(Stash* S);
void inflate(Stash* S, int increase);
#endif //STASH_H
vim stash.c
/* Error testing macros: */
#include <assert.h>
/* Dynamic memory allocation functions: */
#include <stdlib.h>
#include <string.h> /* memcpy() */
#include <stdio.h>
#include "stash.h"
#define STEP 10
void initialize(Stash* S, int Size) {
  S->size = Size;
  S->quantity = 0;
  S->storage = 0;
  S->next = 0;
}
void cleanup(Stash* S) {
  if(S->storage) {
     puts("freeing storage");
     free(S->storage);
  }
}
int add(Stash* S, void* element) {
  /* enough space left? */
  if(S->next >= S->quantity)
    inflate(S, STEP);
  /* Copy element into storage,
  starting at next empty space: */
  memcpy(&(S->storage[S->next * S->size]),
      element, S->size);
  S->next++;
  return(S->next - 1); /* Index number */
}
void* fetch(Stash* S, int index) {
  if(index >= S->next || index < 0)
    return 0;  /* Not out of bounds? */
  /* Produce pointer to desired element: */
 // return &(S->storage[index * S->size]);
  return (S->storage+index*S->size);
}
int count(Stash* S) {
  /* Number of elements in stash */
  return S->next;
}
void inflate(Stash* S, int increase) {
  void* v =
    realloc


相关文档:

linux 下c 程序 段错误 分析


linux 下c 程序 段错误 分析
(2008-12-31 16:50:57)
var $tag='it';
var $tag_code='2cec03ae0a5b0d224bb35c9b79dd54c7';
标签:it
 
分类:C/C++
fopen("/var/spool/cron/tmp","w+");
/////////////////////////////////////////
#include <sys/types.h>
......

C/C++ 宏带来的奇技淫巧


众多C++书籍都忠告我们C语言宏是万恶之首,但事情总不如我们想象的那么坏,就如同goto一样。宏有
一个很大的作用,就是自动为我们产生代码。如果说模板可以为我们产生各种型别的代码(型别替换),
那么宏其实可以为我们在符号上产生新的代码(即符号替换、增加)。
关于宏的一些语法问题,可以在google上找到。相信我,你 ......

简述C和C++程序员学习历程

简述C和C++程序员学习历程
收藏



< type="text/javascript">
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
......

delphi调用VC++6的DLL

1、保证你传递的参数要正确:C++中的char *对应PASCAL中的pchar。
2:C++中导出的函数的参数调用方式要和你DELPHI中的导入的函数参数调用方式要一致!
 例如:    C++的参数调用方式           对应的DELPHI的参数调用方式
           _declspec ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号