[comp.lang.c] Usual arithmetic conversions

ajw@donk.UUCP (ajw) (05/23/89)

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@aus.hf.intel.com   ...uunet!littlei!intelhf!aus!ajw  "Live malloc or die"

karl@haddock.ima.isc.com (Karl Heuer) (05/26/89)

In article <308@donk.UUCP> ajw@donk.UUCP (ajw) writes:
>This took a few merry hours to find:
>	if (hairy_unsigned_expression >= 0) ...

Is this because (a) you don't use lint, (b) you don't pay attention to the
warning it produces on this, or (c) there were so many lint warnings that it
took hours to find the right one?

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

guy@auspex.auspex.com (Guy Harris) (05/27/89)

>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:

"lint" probably would have taken less time to find it; it checks for
comparisons such as "unsigned >= 0".

diamond@diamond.csl.sony.junet (Norman Diamond) (05/29/89)

In article <308@donk.UUCP> ajw@donk.UUCP (ajw) writes:

>>This took a few merry hours to find:
>>	if (hairy_unsigned_expression >= 0) ...

In article <13396@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes:

>Is this because (a) you don't use lint, (b) you don't pay attention to the
>warning it produces on this, or (c) there were so many lint warnings that it
>took hours to find the right one?

>Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

Good idea!  ... <brainstorm> ...

OK, from now on, we all e-mail our programs to Karl Heuer for checking...

:-)

--
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.co.jp@relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-implementing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?

ajw@donk.UUCP (ajw) (06/01/89)

In article <13396@haddock.ima.isc.com>, karl@haddock.ima.isc.com (Karl Heuer) writes:
> In article <308@donk.UUCP> ajw@donk.UUCP (ajw) writes:
> >This took a few merry hours to find:
> >	if (hairy_unsigned_expression >= 0) ...
> 
> Is this because (a) you don't use lint, (b) you don't pay attention to the
> warning it produces on this, or (c) there were so many lint warnings that it
> took hours to find the right one?

Ahem! In this case, the first, actually (working program, hadn't changed a line
of code, etc.etc.)  I am roundly castigated; I have broken the first commandment
(UT version, not OT); I am a worm, and no man; a byword and a laughing stock.

Anyway - when I _did_ run lint on this function, it not only told me about the
unsigned comparison, but it called me a degenerate!! I mean, I don't mind being
scolded by _Walking_ lints, but PROGRAMS fer Chrissake?

Colon Hyphen RightParen.

> Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint

-- 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@aus.hf.intel.com   ...uunet!littlei!intelhf!aus!ajw  "Live malloc or die"

bet@bent (Bennett Todd) (06/13/89)

In article <1702@auspex.auspex.com>, guy@auspex (Guy Harris) writes:
>>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:
>
>"lint" probably would have taken less time to find it; it checks for
>comparisons such as "unsigned >= 0".

I used to use lint meticulously. Then I started using ANSI style C.
Anybody got an ANSI supporting version of lint handy? GCC using -Wall is
better than lint for some kinds of warning messages, but that particular
special case in degenerate booleans isn't among the things it knows to
check for (at least the version I am using, 1.34). Maybe I should bring
up agcpp after all....

-Bennett
bet@orion.mc.duke.edu