rfg@MCC.COM (Ron Guilmette) (03/29/89)
It is often nice that GCC/G++ have a superset of ANSI-C
features. In this case, it is not so nice.
I recently reported in these newsgroups that GCC/G++ seem
to support the notion of "unnamed" fields, even when these
fields are *not* bitfields (as required by ANSI C). Well
perhaps I spoke too soon.
The following program exits with a non-zero exit code because
unnamed fields can be declared but are apparently ignored by
the compiler(s) when allocating space in a structure.
I hope that this will be fixed *not* be deleting the (extension)
feature (which I find very useful) but rather by making it work
for both bitfields and non-bitfields.
----------------------------------------------------------------------
extern void printf (const char*, ...);
extern void exit (int);
int test ();
int errors = 0;
void main ()
{
exit ( (test () || errors) ? 1 : 0);
}
struct struct_1 {
int ;
int ;
int ;
int field1;
};
struct struct_1 structure_var;
int offset;
int test ()
{
offset = (int) &structure_var.field1 - (int) &structure_var;
if (offset == 12 && sizeof (struct struct_1) == 16)
return 0;
else
return -1;
}
-----------------------------------------------------------------------
// Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project
// 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740
// ARPA: rfg@mcc.com
// UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg