This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/17214] New: Compatible structures aren't
- From: "terra at gnome dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Aug 2004 17:32:56 -0000
- Subject: [Bug c/17214] New: Compatible structures aren't
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
File foo1.c:
struct Foo {
struct Foo1a {
char c;
int x : 1; // named
} foo;
char c;
};
int get_foo_c (struct Foo *pfoo) { return pfoo->c; }
----------------------------------------------------------------------------
File foo2.c:
struct Foo {
struct Foo1a {
char c;
int : 1; // unnamed
} foo;
char c;
};
extern int get_foo_c (struct Foo *pfoo);
#include <stdio.h>
int main (int argc, char **argv)
{
struct Foo foo;
foo.c = 42;
printf ("%d\n", get_foo_c (&foo));
return 0;
}
----------------------------------------------------------------------------
The two struct Foos are compatible as per 6.2.7. Thus the above program should
print 42. It doesn't. (Well, it accesses uninitialized memory, so it might.)
The sizes of the two structures aren't even the same.
Either the standard is wrong -- it says that name or no name doesn't matter --
or else the ABI is wrong -- it says alignment and thus the size of the inner
structure is affected by the name.
6.2.7 says
... For two structures,
corresponding members shall be declared in the same order.
For two structures or unions, corresponding bit-fields shall
have the same widths. ...
Not a word about bitfield names, nor even a requirement that names when
present match.
--
Summary: Compatible structures aren't
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: terra at gnome dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: sparc-sun-solaris2.8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17214