unsigned char -> unsigned int conversion

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Mon Jun 18 14:14:03 AEST 1984


While testing the assertion that ``unsigned char'' types propagate
the ``unsigned''ness into expressions, I discovered something very
interesting in the 4.1BSD (PCC) C compiler.  The compiler emits
``.long''s in the assembly output!  Here's a sample:

	unsigned char foo = 1;

	main() {
		if ((-1 | foo) > 0)
			printf("hi there\n");
	}

PCC output (slightly edited):

		.data
		.globl	_foo
	_foo:
		.long	0x1
		.data	1
	L19:
		.ascii	"hi there\12\0"
		.text

		.align	1
		.globl	_main
	_main:
		.word	L13
		movzbl	_foo,r0
		bisl2	$-1,r0
		jeql	L17
		pushl	$L19
		calls	$1,_printf
	L17:
		ret
		.set	L13,0x0
		.data

Further experimentation shows that all ``static'' variables, and all
initialized variables, are generated with a minimum size of 4 bytes.
This apparently includes arrays as well (but ``char c[8]'' doesn't
generate 32 bytes).

I guess PCC is trying to keep things longword-aligned.

As to the original point, we can see from the ``jeql'' (as opposed to
``jgtr'') that PCC *does* propagate the unsigned attribute.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list