Copyright 2004 by M. Uli Kusterer Tue, 30 Dec 1969 07:58:58 GMT Comments on article blog-c-parameter-evaluation-order at Zathras.de http://www.zathras.de/angelweb/blog-c-parameter-evaluation-order.htm blog-c-parameter-evaluation-order Comments witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) en-us Comment 6 by JJ http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment6 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment6 This is NOT platform-specific OR compiler-specific. This is completely undefined behavior because you are reading and modifying 'myString' with no sequence point in between. Do not write code like this (it is wrong) and do not teach others to write code like this either.

Please read up on sequence points and understand what "undefined behavior" is (which is what gcc -Wmost is telling you). Undefined means you should never do it because it is always wrong. If this was merely "implementation-defined behavior" then yes, you could claim it was platform or compiler dependent, depending on which implementation defined the semantics for you.
Comment 5 by Uli Kusterer http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment5 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment5 Uli Kusterer writes:
Mike Ash recently posted a neat additional link about this topic that clears up the confusion some may have between the function parameter separator "," and the ","-operator used in expressions: http://c-faq.com/expr/comma.html

Comment 4 by Dan http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment4 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment4 Dan writes:
Aha! Thanks for this useful information. I was trying to work out what this compiler warning was trying to warn me about, and your explanation clarified it straightforwardly.
Comment 3 by ezj http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment3 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment3 Thanks, great info. I assumed left-to-right processing in a collection of printf arguments, and fortunately noticed some funky results. Turns out your post nailed the issue.
Comment 2 by Uli Kusterer http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment2 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment2 Uli Kusterer writes:
@Drew: Good point, it really is compiler-dependent. Even though platform details like the CPU and the operating system's ABI may set the general guidelines by which compilers get implemented, different levels of optimization may be implemented in different compilers, and different compilers may use slightly different algorithms. As long as everything ends up on the stack in the correct order, or in the correct registers, most compilers can do this any way they want.
Comment 1 by Drew Thaler http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment1 http://zathras.de/angelweb/blog-c-parameter-evaluation-order.htm#comment1 Drew Thaler writes:
I don't think it's platform-dependent so much as it is compiler-dependent. gcc-x86 does one thing, gcc-ppc does something else. CodeWarrior-ppc or xlc-ppc might have another behavior.

This is where warnings are useful. gcc's -Wmost will say:
warning: operation on 'myString' may be undefined