A simple non-portable expression tha

Tim Smith tim at ism780c.UUCP
Tue Apr 22 11:37:19 AEST 1986


When I ask various people about what compilers can do to

	LONG + INT1 + INT2

I get two different answers.  The first is that the compiler can
play games with associativity and commutativity before it changes
the ints to longs.  The second is that it must change INT2 to a
long because of the left associative nature of addition.  Then it
can use associativity and commutativity to change things.

Reading K&R, I can convince myself of either answer.

If the first case is correct, then this is a non-portable expression,
and I think lint should warn about it.

In the second case, there is no problem with that expression, but how
about this one:

	INT1 + INT2 + LONG

I should have used this one in my original posting.  On a machine with
different sizes for ints and longs, this expression can have problems.
Lint says nothing about this.  Is this a problem with lint, or am
I (again) putting my foot in my mouth?
-- 
Tim Smith       sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim



More information about the Comp.lang.c mailing list