Parenthesis error in 4.2bsd c compiler

Alain Williams addw at root44.UUCP
Wed Sep 5 03:19:24 AEST 1984


<gobble-gobble>
I ran the following on a few machines:
main()
{
	unsigned u, u2;
	int	m_7 = -7, two = 2, i, j;
	u = m_7;
	i = (u % two);
	j = ((int) u) % two;
	printf("%u %d %d %d %d\n", u, (int) (u%two), i, (u%two), j);
}

Machine, O/S	Result
Vax 4.2bsd	4294967289 -1 1 1 -1
PDP11/44 S III	65529 1 1 1 -1
68000 S 5	4294967289 1 1 1 -1

Note the second number printed in each case.
Why does the Vax treat '(int) (u%two)' as '((int) u) % two' ????
Most annoying.

	Alain Williams,
	Root Computers Ltd, London.
	{ENGLAND}!hirst1!root44!addw
	edai!root44!rootis!addw
	ukc!root44!addw



More information about the Comp.lang.c mailing list