Comments on: How post-increment & pre-increment both are evaluated in function argument? /c-language-programming-tips/what-is-the-sequence-of-parameters-to-be-printed-in-printf-for-gcc-compiler-in-linux/ Because one technology can make another technology rich Fri, 25 May 2012 23:21:19 +0000 hourly 1 http://wordpress.org/?v=3.3.2 By: jigar /c-language-programming-tips/what-is-the-sequence-of-parameters-to-be-printed-in-printf-for-gcc-compiler-in-linux/#comment-6 jigar Tue, 27 Sep 2011 10:05:40 +0000 /?p=131#comment-6 As per c standard "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 accessed only to determine the value to be stored." There is a sequence point before evaluating the arguments to a function, and a sequence point after all the arguments have been evaluated (but the function not yet called). Between those two (i.e., while the arguments are being evaluated) there is not a sequence point (unless an argument is an expression includes one internally, such as using the && || or , operator). That means the call to printf is reading the prior value both to determine the value being stored (i.e., the a++) and to determine the value of the second argument (i.e., the a++) and also 3rd argument (i.e the ++a). This clearly violates the requirement quoted above, resulting in undefined behavior. As per c standard

“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 accessed only to determine the value to be stored.”

There is a sequence point before evaluating the arguments to a function, and a sequence point after all the arguments have been evaluated (but the function not yet called). Between those two (i.e., while the arguments are being evaluated) there is not a sequence point (unless an argument is an expression includes one internally, such as using the && || or , operator).

That means the call to printf is reading the prior value both to determine the value being stored (i.e., the a++) and to determine the value of the second argument (i.e., the a++) and also 3rd argument (i.e the ++a). This clearly violates the requirement quoted above, resulting in undefined behavior.

]]>
By: saurabh /c-language-programming-tips/what-is-the-sequence-of-parameters-to-be-printed-in-printf-for-gcc-compiler-in-linux/#comment-5 saurabh Tue, 27 Sep 2011 09:49:17 +0000 /?p=131#comment-5 but how differ?? what is the logic behind this on Linux but how differ?? what is the logic behind this on Linux

]]>
By: jigar /c-language-programming-tips/what-is-the-sequence-of-parameters-to-be-printed-in-printf-for-gcc-compiler-in-linux/#comment-4 jigar Tue, 27 Sep 2011 09:30:47 +0000 /?p=131#comment-4 compile it with gcc -Wall filename.c compiler will give warning as its undefined behaviour. for operation on a. output of this program will differ on different system ..!! compile it with gcc -Wall filename.c

compiler will give warning as its undefined behaviour. for operation on a.

output of this program will differ on different system ..!!

]]>