引用 :
在VS2008编译有问题,下面测试是OK的
#include
#include "form.h"
#include
#include
#include
void **darray_new(int row, int col, int size)
{
void **arr;
arr = (void **) malloc(sizeof(void *) * row + size * row * col);
if (arr != NULL)
{
void *head;
head = (void *)(arr + sizeof(void *) * row);
memset(arr, 0, sizeof(void *) * row + size * row * col);
while (row--)
arr[row] = (unsigned char*)head + size * row * col;
}
return arr;
}
void darray_free(void **arr)
{
if (arr != NULL)
free(arr);
}
struct student
{
char name[128];
int pid;
};
//struct xxx **x;
//x = (struct xxx **) darray_new(5, 4, sizeof(struct xxx));
int main(int argc, char **argv)
{
struct student **sd;
sd = (struct student **) darray_new(5, 4, sizeof(struct student));
strcpy(sd[1][3].name,"ass");
sd[1][3].pid = 100;
strcpy(sd[1][4].name,"ccccc");
sd[1][4].pid = 101;
char *pStr = "master";
int f = 12345;
int *n = &f;
qDebug() << "char = " << pStr + 1 << "int = " << *(n+1);
darray_free(sd);
QApplication app(argc, argv);
Form form;
form.show();
return app.exec();
}
阅读(1397) | 评论(1) | 转发(0) |