1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C standard semantics ambiguity

Discussion in 'C' started by metahuman, Feb 27, 2008.

  1. metahuman

    metahuman New Member

    Joined:
    Feb 8, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    int k = 0; int g() { k = k + 1; return k; }
    int D[] = {13, 19, 47, 3, 7};
    …..
    D[ g() ] = D[ g() ]++  —  D[ g() ]++;

    According to a book from which this problem comes this code will generate 5 to 6 different results according to different implementations of the C standard semantics...

    I have found 2 results based on Visual studio and GCC C compilers: Those are
    D={13,20,48,-28,7} Visual studio
    D={13,44,48,4,7} GCC

    This is obviously due to the order of execution of the assignment operator.

    I am not able to determine what 4 other set of values can be obtained using the standard C semantics. :embarasse

    The book gives a hint that it has to do with the assignment operator and one rule in Standard C semantics... it's not related to associativity ..................... This makes it even more confusing :nonod:
     

Share This Page