Usual arithmetic conversions

ajw ajw at donk.UUCP
Tue May 23 04:57:25 AEST 1989


Don't you just hate it when code that has been working for years
suddenly goes bad on you?  This took a few merry hours to find:

if (buf_size - (used_so_far + this_record_size + trailer_size) >= 0)
	enough_room_left();

"trailer_size" is in fact #defined as an expression which deep in its
bowels includes a 'sizeof'.  My new compiler (quite properly, I have no
doubt), treats 'sizeof' as unsigned, with the result that the entire
expression in the 'if' statement becomes unsigned, and thus the condition
is always true.

Trivial, I know, but hey, it beats chundering on about summing pointers.

-- Alan Waldock, just offering individual opinions while happening to work at 
Intel Corp, M/S HF2-37, 5200 NE Elam Young Pkwy, Hillsboro, Oregon 97124-6497
ajw at aus.hf.intel.com   ...uunet!littlei!intelhf!aus!ajw  "Live malloc or die"



More information about the Comp.lang.c mailing list