The memory returned with malloc() that you assigned to the pointer to the structure with a zero-length array element will be aligned in memory ..., which is required by the C99 specification. Thus, there is no problem with imposing a structure with an array of zero length from memory allocated from the heap via malloc() .
If you encounter a problem, you will try to overlay your structure on top of some raw buffer in memory that comes from a packaged or not traditionally aligned data source, such as a file header, memory-mapped interface, etc. In these cases, using an array with zero length for variable-length data processing may be a bad idea, because the data cannot be aligned according to the default alignment parameters of the platform, and thus the offset to the array is not goes to the correct results.
source share