Re: if (blah) ...

From: Chris Proctor (cjp@minotaur.labyrinth.net.au)
Date: 08/11/99


At 05:43 AM 8/12/99 +0400, you wrote:
>Hi!
> > 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.

You miss my point entirely.
if (blah) is sometimes true even if blah == NULL.
And this is not my code here either, stock (bpl11).
if (blah != NULL) actually performs as expected, where if (blah) doesn't.

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

Certainly should do, from my own experience, but doesn't seem to at times
for some unknown reason.
Changing the:
for (d = descriptor_list; d && d->desc_num != num_to_dc; d = d->next);
to
for (d = descriptor_list; d != NULL && d->desc_num != num_to_dc; d = d->next);

Has stopped the occasional crashes when disconnecting idle sockets.

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

It certainly _was_.
Regards,
Chris Proctor (Deathblade, Implementor of DominiaMUD)
MUD Homepage: http://www.labyrinth.net.au/~cjp


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



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