struct array initialize with a variable

85 views Asked by At

I am trying to create an array with a known size.

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

here this gives me null result for the struct array; AudioStreamPacketDescription tempDesc[packetsFilledDesc];

enter image description here

if I do AudioStreamPacketDescription tempDesc[24];

it gives me correct value;

enter image description here

how can I initialize array size with a variable?

1

There are 1 answers

1
Tlacenka On

If this is a C code, I would dynamically allocate the array:

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