On Mon, 7 Oct 2024 02:32:13 -0000 (UTC), Kaz Kylheku wrote:
> I can't think of a reasonable interpretation of the original wording
> which would allow the size to be other than the offset of the array,
> when the array is of a character type.
>
> The current wording clearly does allow the size to go beyond the offset
> in that case.
The original wording includes no requirement that the offset of the
replacement array used for the size calculation has any relationship
whatsoever with the offset of the flexible array member.
For example, in
struct foo { int a; char b; char c[]; };
in many real-world implementations the offset of c is 5 but the size
of the structure is 8. On these implementations, the size matches the
offset of c in a similar structure where c is replaced by a length-1
array of int, and also matches the size of a similar structure with c
deleted, so this is consistent with old and new wordings.
I don't think the updated wording alters any implementation requirement,
but it does seem quite a bit less complicated to explain.
> Don't get burned: don't rely on the size of a flexible array struct.
> Use the offsetof that flexible member.
An evil compiler could probably make the size less than the offset
of the flexible array member and be conforming, with both old and
new wordings. This would break some examples but an evil compiler
obviously won't care about non-normative trivialities like examples.
So you need to use offsetof when porting to the DeathStation 9000.
Otherwise avoid evil compilers and the handful of extra bytes to
some malloc calls probably makes no practical difference.
|
|