Do all arrays have to have a pad byte after them?
Dave Brolley
brolley@cygnus.com
Thu Nov 12 17:04:00 GMT 1998
While comparing the pointers one past the end is defined, dereferencing
them is not. There is no need for a padding byte to actually be allocated
in memory. Even so, I would expect the test to print "failed" when
compiled with most compilers.
Dave
Hyman Rosen wrote:
> 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