我正在进行全局结构数组的实现。现在问题可能是也可能不是这个"测试"只分配这些数组的一个元素。所以我希望有人知道我做错了什么。我的全局目标是使用free()和realloc
实现动态大小的动态数组亲切的问候
typedef struct IntegerBuffer {
unsigned DataSize;
}IntegerBuffer;
void PrintDummy();
void AddBufferSize(size_t Size);
IntegerBuffer *SendIntBuffer = NULL;
int main()
{
AddBufferSize(3);
PrintDummy();
}
void AddBufferSize(size_t Size)
{
unsigned i;
SendIntBuffer = (IntegerBuffer*)malloc(Size*sizeof(IntegerBuffer));
for (i = 0; i < (unsigned)Size; i++)
{
SendIntBuffer[i].DataSize = i;
}
return;
}
void PrintDummy()
{
unsigned size = (sizeof(SendIntBuffer) / sizeof(SendIntBuffer[0]));
for (unsigned i = 0; i < size; i++)
{
printf("\nTestprint %i", SendIntBuffer[i].DataSize);
}
return;
}