pBuf[i++] = Calc(pBuf, i);

Discussion in 'C Programming' started by Sven K?hne, Oct 22, 2003.

  1. Sven K?hne

    Sven K?hne Guest

    Hello *,

    Our new compiler has some problems with this line:

    pBuf[i++] = Calc(pBuf, i);

    The Assembler-Code generated uses the increases "i" as a Paramter in
    Calc. Our old Compiler did not do this. So who is right.

    And where is the lay (ANSI-C Definition) written ans available, that
    says ist is rigth, and this is wrong?

    Thanks, Sven
    Sven K?hne, Oct 22, 2003
    #1
    1. Advertising

  2. Sven K?hne

    Jonas Guest

    "Sven K?hne" <> wrote in message
    news:...
    > Hello *,
    >
    > Our new compiler has some problems with this line:
    >
    > pBuf[i++] = Calc(pBuf, i);


    Order of evaluation is unspecified in above expression (it is actually an
    undefined statement). So you should not write code like that.

    >
    > The Assembler-Code generated uses the increases "i" as a Paramter in
    > Calc. Our old Compiler did not do this. So who is right.


    Both or none! (see above)

    >
    > And where is the lay (ANSI-C Definition) written ans available, that
    > says ist is rigth, and this is wrong?
    >
    > Thanks, Sven
    Jonas, Oct 22, 2003
    #2
    1. Advertising

  3. On 22 Oct 2003 02:10:48 -0700, in comp.lang.c ,
    (Sven K?hne) wrote:

    >Our new compiler has some problems with this line:
    >
    >pBuf[i++] = Calc(pBuf, i);
    >
    >The Assembler-Code generated uses the increases "i" as a Paramter in
    >Calc. Our old Compiler did not do this. So who is right.


    Probably neither. See section 3.1 of the FAQ.

    You'll need to rewrite the expression so that it gives you the answer
    you want without relying on undefined behaviour .

    >And where is the lay (ANSI-C Definition) written ans available, that
    >says ist is rigth, and this is wrong?


    ISO C standard 6.5.2
    Between the previous and next sequence point an object shall have its
    stored value modified at most once by the evaluation of an expression.
    Furthermore, the prior value shall be read only to determine the value
    to be stored.

    I believe that in the above expression, you are reading it once to
    determine the value to store, and once to pass to a function, and you
    also modify it.
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
    Mark McIntyre, Oct 22, 2003
    #3
    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. Tat
    Replies:
    0
    Views:
    354
  2. Niv
    Replies:
    7
    Views:
    4,883
    OutputLogic
    May 22, 2009
  3. Andy

    Menu printed twice in calc prog

    Andy, Nov 6, 2003, in forum: C Programming
    Replies:
    5
    Views:
    482
    Sheldon Simms
    Nov 7, 2003
  4. tertius

    date diff calc

    tertius, Nov 29, 2004, in forum: Python
    Replies:
    9
    Views:
    573
    David Fraser
    Dec 2, 2004
  5. Kaye Ng

    ruby calc.rb or just calc.rb

    Kaye Ng, Jul 26, 2010, in forum: Ruby
    Replies:
    7
    Views:
    384
    Kaye Ng
    Jul 28, 2010
Loading...

Share This Page