 |
DEF_QUEUE |
Type (Structure) |
A structure describing the header of a variable-sized queue.
Note that Buffer[] is a GNU C extension for variable-sized arrays (TIGCC is GNU C). The
main usage of DEF_QUEUE structure is when you want to allocate a queue dynamically on
the heap (using malloc). The operator sizeof
treats variable-sized arrays as zero-length arrays (this is a sense of zero in square brackets).
So, the following example ilustrates correct allocating of a queue with 100-byte long buffer on the
heap (note that 100-byte long buffer can store 50 entries, because each int entry is 2 bytes long):
DEF_QUEUE *qptr = malloc (sizeof (DEF_QUEUE) + 100);
OSqclear (qptr);
qptr->Size = 50;
OSenqueue (some_data, qptr);
From this example you can see that you need to fill field Size of the queue
structure manually.