egcs and bitfields

Robert Lipe robertlipe@usa.net
Fri Mar 12 08:48:00 GMT 1999


> #include <stdio.h>
> 
> struct foo { int c:3; } x = { 7 };
> 
> int main(void)
> {
>   printf("%d\n", x.c);
> 
>   return(0);
> }
> 
> >>-drakh-> egcc fieldinit.c
> >>-drakh-> ./a.out
> -1
> 
> I think the output should be 7, since an "int"
>  bitfield is supposed
> to be unsigned according to the i386 SysV ABI.

While I can't comment on any correctness issues in the example or
pertinence of various ABI specs, I can confirm that your example behaves
differently on different System V/386's.


On OpenServer: 
	/bin/cc		-1
	egcs 1.1.1 	-1
	icc		7
	udk cc		7 

On UnixWare 7.0.1
	/bin/cc		7
	egcs 1.1.1 	-1


Note that /bin/cc on SVR5 is essentially the same as UDK on OSR5.  Since
/bin/cc on OpenServer had parentage in the code that became those two 
compilers, I'm guessing that it was an intentional ABI change between
the OpenServer lineage (more iBCS2-ish) and the SVR4 lineage.

RJL


More information about the Gcc mailing list