Authors: Jay Ghiron
Date: 2026-10-09
Submitted against: C23
Status: Open
EXAMPLE 3 After the declaration:
struct s { int n; double d[]; };the structure
struct shas a flexible array memberd. A typical way to use this is:int m = /* some value */; struct s *p = malloc(sizeof(struct s) + sizeof(double [m]));and assuming that the call to
mallocsucceeds, the object pointed to bypbehaves, for most purposes, as ifphad been declared as:struct { int n; double d[m]; } *p;(there are circumstances in which this equivalence is broken; in particular, the offsets of member
dcan sometimes not be the same).
(C23 6.7.3.2 "Structure and union specifiers" paragraph 23.)
This example suggests that the offsets of the array members can be different, however this seems to conflict with:
One special guarantee is made to simplify the use of unions: if a union contains several structures that share a common initial sequence (see following sentence), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the completed type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members.
(C23 6.5.3.4 "Structure and union members" paragraph 6.)
The array members are part of the common initial sequence because the array types are compatible and all prior members are the same. Was it the intent to require that flexible array members can be corresponding members in common initial sequences with complete array members, and by extension require the same offset?