Do all arrays have to have a pad byte after them?

Hyman Rosen hymie@prolifics.com
Thu Nov 12 11:43:00 GMT 1998


Section 5.10 of the standard says
"Two pointers of the same type compare equal if and only if they are
both null, both point to the same object or function, or both point
one past the end of the same array."

This seems to imply that all arrays, even those in structures, require
at least one byte of padding to separate the past-the-end pointer of
one from the beginning of the next.

So the following code should print "succeeded", but it prints "failed"
with the latest egcs (on Linux).

///////////////////////// pcmp.cc //////////////////////////
extern "C" int printf(const char *, ...);
int main()
{
	struct { char a[8], b[8]; } z;
	bool b = &z.a[8] == &z.b[0];
	printf("%s\n", b ? "failed" : "succeeded");
}



More information about the Gcc-bugs mailing list