Re: [Code] Brainteaser

From: Mike Breuer (mbreuer@new.rr.com)
Date: 11/21/01


----- Original Message -----
From: "John" <witpens@OPTUSHOME.COM.AU>


> What is the difference between:-
> if (!str || !*str) return;
> and
> if (!str) return;
> else if (!*str) return;

In effect, nothing.  The top choice is a tiny bit more efficient.  Also, the
else in the second choice is not necessary, since that line will never be
executed when the top if condition is true.  Here's a more detailed
explanation of what's going on:

Option 1:
Conditionals are always evaluated left to right, except when operator
precedence demands otherwise.  Once it can be determined that the entire
expression will evaluate either true or false, then no further testing takes
place.  So, if !str is true, !*str will never be tested, since the
expression must be true regardless.

Option 2:
In this case, the conditions are tested separately by explicit design, but
the effect is the same.  if !str is true, we return and no further testing
takes place.  Otherwise !*str is tested to see whether we should return.

I can't imagine why changing that line stopped your MUD from crashing.  I
suspect you did something else that stopped the crashing (or it hasn't
really stopped, and you just haven't determined the proper conditions).  To
test that, try changing it back and see if it starts crashing again.

Mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST