cc1 accepts struct redeclarations

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sun Feb 6 04:57:00 GMT 2000


> Which it seems to be. But I guess gcc 2.95.2 doesn't do what the author
> expected from it. I don't know enough about the standarts to know what it
> should do in a case like that, but think it's just plain wrong.

Apparently, the problem is of the form

struct A{
};

struct A{
  int i;
  int j;
};

int main()
{
  int i = 1;
  struct A a;
  memset(&a,0,sizeof(a));
}

This is incorrect code, yet gcc accepts it (it rejects it if the first
definition has fields). Under -pedantic, it warns about the empty
struct, but not about the redeclaration.

So, there is a bug in the C library; it should not use empty
structs. There is also a bug in GCC, which does not detect the error,
but silently generates bad code.

In glibc 2.1, this bug is fixed.

Regards,
Martin


More information about the Gcc-bugs mailing list