Re: Pre and post increment

2009-07-20 Thread Ian Lance Taylor
i...@adari.net writes: > 1. It is wise then to insure that the final value of an expression is > ascertained upfront before it is being used in a function call as an > argument. I suppose this is applicable in all cases of expressions > and not limited to pre and post increments, although, pre an

Re: Pre and post increment

2009-07-20 Thread imap
1. It is wise then to insure that the final value of an expression is ascertained upfront before it is being used in a function call as an argument. I suppose this is applicable in all cases of expressions and not limited to pre and post increments, although, pre and post is where there is likely

Re: Pre and post increment

2009-07-20 Thread Andrew Haley
Andreas Schwab wrote: > Zachary Turner writes: > >> So if a=5 before a function call, then foo(++a, ++a), might invoke >> foo(6, 6), foo(6, 7), or foo(7, 6). > > Or even foo(42, 666). Or demons might fly out of your nose. Andrew.

Re: Pre and post increment

2009-07-20 Thread Andreas Schwab
Zachary Turner writes: > So if a=5 before a function call, then foo(++a, ++a), might invoke > foo(6, 6), foo(6, 7), or foo(7, 6). Or even foo(42, 666). Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for somet

Re: Pre and post increment

2009-07-20 Thread dharmendra pandit
As the C specification document specifies in section 6.5.2.2 point no 10: The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call. Therefore if in any function cal

Re: Pre and post increment

2009-07-20 Thread Manuel López-Ibáñez
2009/7/20 : > Hello Andrew, > > Thanks for your suggestion, but no difference in output. > > Question: Did you expect different output too? Not really. Although it may occur with different compiler versions or flags. See http://en.wikipedia.org/wiki/Sequence_point and http://c-faq.com/expr/seqpo

Re: Pre and post increment

2009-07-20 Thread Zachary Turner
On Mon, Jul 20, 2009 at 10:30 AM, wrote: > Hello, > > Here is a program with output in gcc (4.3.2) on pre and post increments: > > //code begin > #include > > main () { >    int a; >    a=1; printf ("1. %d %d\n", ++a, a);            

Re: Pre and post increment

2009-07-20 Thread Andrew Pinski
On Mon, Jul 20, 2009 at 8:48 AM, wrote: > Hello Andrew, > > Thanks for your suggestion, but no difference in output. > > Question: Did you expect different output too? Oh the warnings are telling you, your code is undefined. -- Pinski PS gcc-h...@gcc.gnu.org is a better mailing list for these t

Re: Pre and post increment

2009-07-20 Thread imap
Hello Andrew, Thanks for your suggestion, but no difference in output. Question: Did you expect different output too? Thanks Quo ting Andrew Pinski : > On Mon, Jul 20, 2009 at 8:30 AM, wrote: > > Hello, > > > > Here is a program with output in gcc (4.3.2) on pre and post increments: > > Try

Re: Pre and post increment

2009-07-20 Thread Andrew Pinski
On Mon, Jul 20, 2009 at 8:30 AM, wrote: > Hello, > > Here is a program with output in gcc (4.3.2) on pre and post increments: Try using -Wsequence-point. With that option GCC produces: t.c:6: warning: operation on 'a' may be undefined (and many warnings of the same wording for every line afterwa

Pre and post increment

2009-07-20 Thread imap
Hello, Here is a program with output in gcc (4.3.2) on pre and post increments: //code begin #include main () { int a; a=1; printf ("1. %d %d\n", ++a, a); // 1. 2 2 a=1; printf ("2. %d %d\n", a, a++)