Suppose we have the source:
#include <stddef.h>
struct foo
{
char b ;
char a [ SIZE_MAX ] ;
} ;
int main ( void )
{
const size_t z = sizeof ( struct foo ) ;
printf("%zun", z);
return 0 ;
}
What behavior can be expected from the compiler with respect to sizeof (struct foo)
? There can be no object of type struct foo
, since it’s size would be greater than SIZE_MAX
.
I do not find this case covered in the discussion of the sizeof
operator in the (draft) C17 Standard (N2176).
I am using a version of gcc (outdated) that claims to adhere to the C11 standard (and, AFAICT, it does). It fails to compile and reports that struct foo
is too big. That seems reasonable, but is such source guaranteed not to compile, given adherence to the standard? I would be interested in answers specific to particular standards.