Gives me 6 (g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3) On Tue, Jun 8, 2010 at 2:29 PM, Ankur Sinha <[email protected]> wrote:
> On Tue, 2010-06-08 at 19:05 +1000, Andrian Kurniady wrote: > > This is probably incorrect. See > > > http://en.wikipedia.org/wiki/Unspecified_behavior#Order_of_evaluation_of_subexpressions > > I think in C/C++ there is no guarantee that the left part (i++) is > > going to be evaluated before the right part (i--). This behavior can > > be different between compilers. This has nothing to do with operator > > precedence. > > > > Such ordering in Java is more strictly defined, but not in C/C++. > > > > See also: > > http://forums.topcoder.com/?module=Thread&threadID=673205 (similar > > case in C/C++). > > > > -Kurniady > > > > hey, > > The simplest way would be to run it and check. GCC tells me its stupid > code and refuses to compile with my set of flags ;) > > Here's the code: > > > > #include <stdio.h> > > > > int main(){ > > int i = 3; > > i = i++ + i--; > > > > printf("i is %d\n",i); > > > > return 0; > > } > > > The compilation output: > > > > [an...@localhost code]$ gcc -Wall -Werror -W -Wextra -pedantic -ansi > > posttrial.c -o posttrial > > > > cc1: warnings being treated as errors > > posttrial.c: In function ‘main’: > > posttrial.c:29: error: operation on ‘i’ may be undefined > > posttrial.c:29: error: operation on ‘i’ may be undefined > > (line 29 is the i = i++ + i-- statement) > > regards, > Ankur > > -- > You received this message because you are subscribed to the Google Groups > "google-codejam" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-code%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-code?hl=en. > > -- Muhammad Shuaib Khan -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
