Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   C standard semantics ambiguity (http://www.go4expert.com/forums/c-standard-semantics-ambiguity-t9076/)

metahuman 28Feb2008 04:54

C standard semantics ambiguity

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:

All times are GMT +5.5. The time now is 21:11.