"Karl Heinz Buchegger" <kbuchegg@gascad.at> wrote in message
news:4076B7DC.4BEC7B4D@gascad.at...[color=blue]
> William Payne wrote:[color=green]
> >
> > Consider the following code:
> >
> > struct foo
> > {
> > char* bar;
> > };
> >
> > // fooptr is of type foo*
> > if(fooptr != NULL && fooptr->bar != NULL)
> > {
> > cout << fooptr->bar << endl;
> > }
> >
> > Is the if-statement safe, meaning it won't try to evaluate fooptr->bar[/color][/color]
if[color=blue][color=green]
> > fooptr is NULL? Can I make sure it is evaluated from left to right or[/color][/color]
should[color=blue][color=green]
> > I have nested if-statements instead?
> >[/color]
>
> In x && y, it is guaranteed that y is not evaluated if x is already false.
> Same for x || y : if x is already true, y is not evaluated at all.
>
> Which books are you using, that do not mention 'shortcut evaluation' ?
>
>
> --
> Karl Heinz Buchegger
>
kbuchegg@gascad.at[/color]
Thanks for the quick reply, Karl. No need for a nested if-statement then,
just as I thought. And to answer your question: I don't have access to a C++
text except Josuttis Standard Library Book at the moment. =/
/ William Payne