[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] flexmember: update comment

From: Bruno Haible
Subject: Re: [PATCH] flexmember: update comment
Date: Sat, 25 May 2019 00:17:11 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-145-generic; KDE/5.18.0; x86_64; ; )

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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]