4 ms·
BTW, the use of a size 1 array in the struct is a common 'hack', which has some form of dynamic arrays in structs. When the object is allocated through malloc,
by sapeint 6y ago
BTW, the use of a size 1 array in the struct is a common 'hack', which has some form of dynamic arrays in structs. When the object is allocated through malloc, the size of the struct is actually smaller than the size you want for the array, so you allocate the size you want for the struct and add it to the size you want for the array. You can then access this memory after the structure, since it's technically allocated a part of it. As to why it is size 1, and not size 0, some compilers don't accept a size 0 array, so it's probably size 1 to ensure compatibility with those compilers. This is commonly referred to as the 'C Struct Hack'.