Effects on Size and Padding A flexible array member is treated as having no size when calculating the size of a structure, though padding between that member and the previous member of the structure may still exist: /* Prints "8,8" on my machine, so there is no padding. */ printf("%zu,%zu\n", sizeof(size_t), sizeof(struct ex1)); /* Also prints "8,8" on my machine, so there is no padding in the ex2 structure itself. */ printf("%zu,%zu\n", sizeof(struct ex2_header), sizeof(struct ex2)); /* Prints "5,8" on my machine, so there are 3 bytes of padding. */ printf("%zu,%zu\n", sizeof(int) + sizeof(char), sizeof(struct ex3)); The flexible array member is considered to have an incomplete array type, so its size cannot be calculated using sizeof.
Effects on Size and Padding
A flexible array member is treated as having no size when calculating the size of a structure, though padding
between that member and the previous member of the structure may still exist:
/* Prints "8,8" on my machine, so there is no padding. */
printf("%zu,%zu\n", sizeof(size_t), sizeof(struct ex1));
/* Also prints "8,8" on my machine, so there is no padding in the ex2 structure itself. */
printf("%zu,%zu\n", sizeof(struct ex2_header), sizeof(struct ex2));
/* Prints "5,8" on my machine, so there are 3 bytes of padding. */
printf("%zu,%zu\n", sizeof(int) + sizeof(char), sizeof(struct ex3));
The flexible array member is considered to have an incomplete array type, so its size cannot be calculated using
sizeof.
Step by step
Solved in 4 steps with 2 images