| View previous topic :: View next topic |
| Author |
Message |
Jason Heyes Guest
|
Posted: Tue Dec 21, 2004 7:16 am Post subject: Evaluating expressions with side effects. |
|
|
Are the side effects of evaluating expr1 resolved before expr2 is evaluated?
if (expr1 && expr2)
Thanks.
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Tue Dec 21, 2004 7:36 am Post subject: Re: Evaluating expressions with side effects. |
|
|
* Jason Heyes:
| Quote: | 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! ;-)
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
|
|
| Back to top |
|
 |
Jason Heyes Guest
|
Posted: Tue Dec 21, 2004 7:44 am Post subject: Re: Evaluating expressions with side effects. |
|
|
"Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote
| Quote: | * 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! ;-)
|
I rarely need to refer to the standard directly (never, in fact). So why
should I start now?
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Tue Dec 21, 2004 7:57 am Post subject: Re: Evaluating expressions with side effects. |
|
|
* Jason Heyes:
| Quote: | "Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote in message
news:41c7d23a.498078062 (AT) news (DOT) individual.net...
* 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! ;-)
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.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
|
|
| Back to top |
|
 |
Jason Heyes Guest
|
Posted: Tue Dec 21, 2004 8:17 am Post subject: Re: Evaluating expressions with side effects. |
|
|
"Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote
| Quote: | * Jason Heyes:
"Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote in message
news:41c7d23a.498078062 (AT) news (DOT) individual.net...
* 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! ;-)
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.
|
Does this mean I can't ask questions here anymore?
|
|
| Back to top |
|
 |
Sharad Kala Guest
|
Posted: Tue Dec 21, 2004 8:38 am Post subject: Re: Evaluating expressions with side effects. |
|
|
"Jason Heyes" <jasonheyes (AT) optusnet (DOT) com.au> wrote in message
| Quote: | "Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote in message
asking others to do it for you.
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
|
|
| Back to top |
|
 |
Siemel Naran Guest
|
Posted: Tue Dec 21, 2004 10:15 am Post subject: Re: Evaluating expressions with side effects. |
|
|
"Jason Heyes" <jasonheyes (AT) optusnet (DOT) com.au> wrote
| Quote: | 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.
|
|
| Back to top |
|
 |
Jason Heyes Guest
|
Posted: Tue Dec 21, 2004 12:03 pm Post subject: Re: Evaluating expressions with side effects. |
|
|
"Sharad Kala" <no_spam.sharadk_ind (AT) yahoo (DOT) com> wrote
| Quote: |
"Jason Heyes" <jasonheyes (AT) optusnet (DOT) com.au> wrote in message
"Alf P. Steinbach" <alfps (AT) start (DOT) no> wrote in message
asking others to do it for you.
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.
|
Ok I understand. Where can I get the standard?
|
|
| Back to top |
|
 |
Sharad Kala Guest
|
Posted: Tue Dec 21, 2004 12:16 pm Post subject: Re: Evaluating expressions with side effects. |
|
|
"Jason Heyes" <jasonheyes (AT) optusnet (DOT) com.au> wrote in message
| Quote: | "Sharad Kala" <no_spam.sharadk_ind (AT) yahoo (DOT) com> wrote in message
news:32q5m7F3oj81cU1 (AT) individual (DOT) net...
Ok I understand. Where can I get the standard?
|
http://www.parashift.com/c++-faq-lite/big-picture.html#faq-6.12
Sharad
|
|
| Back to top |
|
 |
Karl Heinz Buchegger Guest
|
Posted: Tue Dec 21, 2004 1:22 pm Post subject: Re: Evaluating expressions with side effects. |
|
|
Siemel Naran wrote:
| Quote: |
"Jason Heyes" <jasonheyes (AT) optusnet (DOT) com.au> wrote in message
news:41c7cdaf$0$1121
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.
|
Note that this is not what the OP was asking about.
In C++ speak the OP asked: Is there a sequence point at &&
--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]
|
|
| Back to top |
|
 |
red floyd Guest
|
|
| Back to top |
|
 |
|