Bug in 4.2Bsd C compiler

Spencer W. Thomas thomas at utah-gr.UUCP
Mon Jul 16 16:21:21 AEST 1984


Index:	lib/ccom 4.2BSD

Description:
	When casting an unsigned bit field to a signed integer, sign extension
	is done.

Repeat-By:
	cc -S the following program.  Note the ext instructions.  Note also that
	this problem does not appear for full size unsigned ints.

main()
{
	int i;
	unsigned short j;
	struct {
		unsigned int a : 3;
	} a;

	i = a.a;
	i = (int)a.a;
	i = j;
	i = (int)j;
}
The (edited) output follows:

_main:
	extzv	$0,$3,_a,-4(fp)
	extv	$0,$3,_a,-4(fp)
	movzwl	-6(fp),-4(fp)
	movzwl	-6(fp),-4(fp)
	ret



More information about the Comp.lang.c mailing list