Hi Paul,
> + Use 'FLEXSIZEOF (struct s, d, N)' to calculate the size in bytes
> + of such a struct containing an N-element array, as both
> + 'sizeof (struct s) + N * sizeof (char)' and
> + 'offsetof (struct s, d) + N * sizeof (char)'
> + might compute a size that can cause malloc to align storage
> + improperly, even in C11.
I'm confused.
1) What is the alignment problem if the array element type is 'char'?
I would understand an alignment problem if it is 'double'. But with 'char'?
'char' has the size 1, and - except on m68k - also the alignment 1.
2) If
(struct s *) malloc (offsetof (struct s, d) + N * sizeof (char))
should be avoided in favour of
(struct s *) malloc (FLEXSIZEOF (struct s, d, N))
don't we need to apply a 'ceil'-like alignment to the malloc result?
Bruno