Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > operator evaluation question

Reply
Thread Tools

operator evaluation question

 
 
linq936@hotmail.com
Guest
Posts: n/a
 
      05-07-2007
Hi,
I see the following description in <<Expert C Programming>>,

the order is defined for && and || and a couple of other operators.
These 2 evaluate their operands in a strict left-to-right oder,
stopping when the result is known.

Is this really true? I think the order is compiler dependent.

Thanks.

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-07-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) said:

> Hi,
> I see the following description in <<Expert C Programming>>,
>
> the order is defined for && and || and a couple of other operators.
> These 2 evaluate their operands in a strict left-to-right oder,
> stopping when the result is known.
>
> Is this really true? I think the order is compiler dependent.


The Standard mandates the order and the short-cut evaluation.
Implementations have no leeway in this regard.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      05-07-2007
(E-Mail Removed) wrote:

> Hi,
> I see the following description in <<Expert C Programming>>,
>
> the order is defined for && and || and a couple of other operators.
> These 2 evaluate their operands in a strict left-to-right oder,
> stopping when the result is known.
>
> Is this really true? I think the order is compiler dependent.


Not for && and || and ?: and the comma-operator it isn't.

--
Far-Fetched Hedgehog
"Never ask that question!" Ambassador Kosh, /Babylon 5/

 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      05-07-2007
(E-Mail Removed) wrote:
> Hi,
> I see the following description in <<Expert C Programming>>,
>
> the order is defined for && and || and a couple of other operators.
> These 2 evaluate their operands in a strict left-to-right oder,
> stopping when the result is known.
>
> Is this really true? I think the order is compiler dependent.
>
> Thanks.
>

Perhaps confusing order and precedence. The language specifies the
precedence of operators; c = a + b for example. + has higher precedence
than = and so (a+b) will be evaluated before the assignment to c.

Order of evaluation is a different issue. Given x = f() + g() makes no
guarantee that f() is evaluated before g(). Compiler decides.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameter evaluation order on operator invocations andreas ames C++ 3 10-23-2006 04:34 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Python Ilias Lazaridis Python 2 04-24-2005 05:29 PM
[EVALUATION] - E04 - jamPersist Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 18 04-09-2005 04:45 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 74 04-04-2005 05:29 PM
Order of evaluation -- clash w/sequentiel expression operator Jan Engelhardt C Programming 3 08-20-2003 09:07 PM



Advertisments