Re: [Code] Brainteaser

From: Martijn Schoemaker (
Date: 11/21/01

John wrote:

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

My first hunch is that 'lazy evaluation' is not used. This means that
the compiler probably fully evaluates every boolean term while the
outcome can already be determined by evaluating part of the terms.

Im plain english : In normal circumstances, with no efficiency you
would first evaluate !str (returns true) then !*str (crashes! but assume
it outputs true) then do the boolean evaluation : true || true = true and

thus return.

With lazy evaluation we know that when we use Or statements that
if any of the terms evaluates to true, the complete boolean comparison
will always be true. So : evaluate !str (returns true), Ah, no need to
look further since the operator is || and immediately return (and in your

case dont crash due to nullpointer dereferencing).

Try to check your compiler settings for 'lazy' or 'full' boolean
evaluation. Most compilers nowadays use lazy evaluation to
improve performance. Some allow you to switch this off because
in some rare circumstances lazy evaluation and optimizing may
result in strange behaviour.


Try : 4000

------ WARNING: This signature contains a VIRUS ! -------

   | FAQ: |
   | Archives: |

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