Does that make sense (Apple documentation)?

Here is a snippet of AppleAudioBufferList 's official documentation (reference information on types of audio data) :

AudioBufferList
Holds an array of variable-length AudioBuffer structures.

struct AudioBufferList {
    UInt32      mNumberBuffers;
    AudioBuffer mBuffers[1];
};
typedef struct AudioBufferList  AudioBufferList;

Fields

mNumberBuffers
The number of AudioBuffer structures in the mBuffers array.

mBuffers
An array of variable-length AudioBuffer structures.

If mBuffersdefined as AudioBuffer[1], it does not have a variable length and, therefore, is mNumberBuffersimplicitly defined as 1.

Am I missing something here or is it just nonsense?

+3
source share
4 answers

Good, because C to C99 requires a nonzero array size.

mBuffers AudioBuffer*, .

mBuffers AudioBuffer, mBuffers[x].

AudioBuffer[1].

C99,

struct AudioBufferList {
    UInt32      mNumberBuffers;
    AudioBuffer mBuffers[];
};

(. C ?.)

+3

, "struct hack" ( C99) " " (VLA). , "1" . , , . , 10 , :

AudioBufferList *a = malloc(sizeof (*a) + 9 * sizeof(AudioBuffer));
a->mNumberBuffers = 10;

, AudioBuffer , , , .

+3

- , PostgreSQL,

// VARIABLE SIZED STRUCTURE

- . , , , , 1 mBuffers - . , realloc() , , , "" mBuffers, .

+2

, , mBuffers[1] - . . , , .

. ..

+2

Source: https://habr.com/ru/post/1737038/


All Articles