struct array使用变量初始化

时间:2015-06-09 17:24:07

标签: ios objective-c arrays struct

我正在尝试创建一个已知大小的数组。

struct  AudioStreamPacketDescription
{
    SInt64  mStartOffset;
    UInt32  mVariableFramesInPacket;
    UInt32  mDataByteSize;
};
typedef struct AudioStreamPacketDescription AudioStreamPacketDescription;

这里给出了struct数组的null结果; AudioStreamPacketDescription tempDesc[packetsFilledDesc];

enter image description here

如果我这样做的话 AudioStreamPacketDescription tempDesc[24];

它给了我正确的价值;

enter image description here

如何使用变量初始化数组大小?

1 个答案:

答案 0 :(得分:0)

如果这是一个C代码,我会动态分配数组:

AudioStreamPacketDescription *tempDesc = malloc (packetsFilledDesc * sizeof(struct AudioStreamPacketDescription));
...
free(tempDesc);