Re: if (blah) ... Proctor on Thu, Aug 12, 1999 at 10:58:13AM +1000

From: Oleg V. Volkov (
Date: 08/11/99

> Noticed an odd thing happening with some of my code (and some stock) since
> moving servers.
> The common construct:
> if (blah)
>    do this;
> else
>    do something else;
> Doesn't seem to work correctly.
> Occasionally it will do "this" instead of "something else" even if "blah"
> is negative or null.

That's right: "something else" will be executed ONLY if blah == NULL.
Even negative gives true.

> I've been fixing up bits of code as I notice them, using:
> if (blah != NULL)
>    do this;
> else
>    do something else;
This equals
if (blah)

> or if (blah > 0), depending on what type of variable blah is.
And this NOT.

> This has caused the most problems in mobact.c, apparently, but was also
> crashing the mud in do_disconnect and a few other places.
> Anyone know why this would suddenly have started happening? Is it to do
> with versions of compilers, operating systems, or something else entirely?

Hmmm, 'twas always that way! Check any C/C++ book.

Oleg V. Volkov aka Rover                              E-mail:
E-mail redirector: (always up)                     -=/ SR 13 /=-

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 12/15/00 PST