operator evaluation question

Discussion in 'C Programming' started by linq936@hotmail.com, May 7, 2007.

  1. Guest

    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.
     
    , May 7, 2007
    #1
    1. Advertising

  2. 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.
     
    Richard Heathfield, May 7, 2007
    #2
    1. Advertising

  3. Chris Dollin Guest

    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/
     
    Chris Dollin, May 7, 2007
    #3
  4. Joe Wright Guest

    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 ---
     
    Joe Wright, May 7, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Engelhardt
    Replies:
    3
    Views:
    381
    Mike Wahler
    Aug 20, 2003
  2. Ilias Lazaridis
    Replies:
    2
    Views:
    406
    Ilias Lazaridis
    Apr 24, 2005
  3. andreas ames
    Replies:
    3
    Views:
    378
    Victor Bazarov
    Oct 23, 2006
  4. Ilias Lazaridis
    Replies:
    74
    Views:
    796
    Ilias Lazaridis
    Apr 4, 2005
  5. Ilias Lazaridis
    Replies:
    18
    Views:
    362
    Bill Guindon
    Apr 9, 2005
Loading...

Share This Page