Evaluating expressions with side effects.

J

Jason Heyes

Are the side effects of evaluating expr1 resolved before expr2 is evaluated?

if (expr1 && expr2)

Thanks.
 
A

Alf P. Steinbach

* Jason Heyes:
Are the side effects of evaluating expr1 resolved before expr2 is evaluated?

if (expr1 && expr2)

Thanks.

Do get yourself a copy of the standard.

The answer is yes, except destruction of temporaries.

Now find which paragraph in the standard says exactly that! ;-)
 
J

Jason Heyes

Alf P. Steinbach said:
* Jason Heyes:

Do get yourself a copy of the standard.

The answer is yes, except destruction of temporaries.

Now find which paragraph in the standard says exactly that! ;-)

I rarely need to refer to the standard directly (never, in fact). So why
should I start now?
 
A

Alf P. Steinbach

* Jason Heyes:
I rarely need to refer to the standard directly (never, in fact). So why
should I start now?

You needed it now, so the 'never' is incorrect.

Presumably the 'rarely' is also incorrect.

You should start now so that you do your work yourself instead of
asking others to do it for you.
 
J

Jason Heyes

Alf P. Steinbach said:
* Jason Heyes:

You needed it now, so the 'never' is incorrect.

Presumably the 'rarely' is also incorrect.

You should start now so that you do your work yourself instead of
asking others to do it for you.

Does this mean I can't ask questions here anymore?
 
S

Sharad Kala

Jason Heyes said:
Does this mean I can't ask questions here anymore?

Not at all. I think the point Alf is making is that to write correct and
authoritative programs one needs to have a copy of Standard. As you may be
aware that not always compilers get correct results. What do you do then ?
The answer is the Holy Standard. But I do agree that if you don't require to
use C++ daily, or in depth then probably Standard is not what you may want
to read. But for a serious C++ programmer it is a must.

Best wishes,
Sharad
 
S

Siemel Naran

Are the side effects of evaluating expr1 resolved before expr2 is evaluated?

if (expr1 && expr2)

Yes, but only if expr1 and expr2 evaluate to fundamental types (eg. bool or
int). This is called short circuting. If expr1 and expr2 evaluate to a
class type with on overload operator&&, then the order is unspecified, as
this is just a function call.
 
J

Jason Heyes

Sharad Kala said:
Not at all. I think the point Alf is making is that to write correct and
authoritative programs one needs to have a copy of Standard. As you may be
aware that not always compilers get correct results. What do you do then ?
The answer is the Holy Standard. But I do agree that if you don't require
to
use C++ daily, or in depth then probably Standard is not what you may want
to read. But for a serious C++ programmer it is a must.

Ok I understand. Where can I get the standard?
 
K

Karl Heinz Buchegger

Siemel said:
Yes, but only if expr1 and expr2 evaluate to fundamental types (eg. bool or
int). This is called short circuting.

Note that this is not what the OP was asking about.
In C++ speak the OP asked: Is there a sequence point at &&
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top