This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
bug, sizeof large union
- To: gcc-bugs at gcc dot gnu dot org
- Subject: bug, sizeof large union
- From: Mitsuhisa Sato <msato at trc dot rwcp dot or dot jp>
- Date: Fri, 30 Jun 2000 14:23:29 +0900
- cc: msato at trc dot rwcp dot or dot jp
Hi,
I found a bug that 'sizeof' a large union is wrong.
If someone alreay reported, let me know how to fix it.
---
union A_ok {
char A[ 0xFFFFFFF];
};
union A_ng {
char A[0x10000000];
};
union A_ng x;
main()
{
printf("size A_ok=%x, size A_ng=%x\n",
sizeof(union A_ok),sizeof(union A_ng));
x.A[0xFFFFFFF] = 1;
}
---
I got results:
size A_ok=fffffff, size A_ng=0
Segmentation fault
'x' in bss is also not allocated correctly.
My gcc version is:
GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
(i386-redhat-linux) compiled by GNU C version egcs-2.91.66
19990314/Linux (egcs-1.1.2 release).
And my system is:
Linux version 2.2.12, Pentium II
I got the same result on :
Sun Enterprise 450 Sparc/Solaris, gcc version 2.95.2 19991024 (release)
Thanks,
-- M. Sato.