By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

short circuited expressions...

P: n/a
Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

....

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?

TIA
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Steven Wong escribió:
I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


It is. Your C++ manual don't say that? Find another.

Regards.
Jul 19 '05 #2

P: n/a

"Steven Wong" <gn*******@yahoo.com> wrote in message
news:a7**************************@posting.google.c om...
Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

...

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


The language standard dicates that it must. However, there's
no possible way it can actually enforce this rule. An implementation
that does not obey it is not conforming, and imo should not be used.

-Mike
Jul 19 '05 #3

P: n/a
In article <a7**************************@posting.google.com >, gndm_2001
@yahoo.com says...
Just wondering, is it portable to write:

something* pSomething = getSomething();

if( pSomething && pSomething->stuff() ) {

...

}

I'm not sure if the condition statement is always shortcircuited for
every implementation of C++?


Yes it is, UNLESS you've overloaded operator&& for the types involved.

If you have something that doesn't short-circuit evaluations like this,
it's not C++ and not really even much like C++ (or C) either -- if I'm
not mistaken, short circuit evaluation has been been part of C since
before the beginning (i.e. back at least as far as B, and quite possibly
to BCPL or even CPL).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.