Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>C and C++ are two completely different languages; don't assume the same rules always apply to both. In the case of parameter evaluation order, however:</p> <p>C99:</p> <blockquote> <b>6.5.2.2 Function calls</b><br> ...<br> 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. </blockquote> <p>[<em>Edit</em>] C11 (draft):</p> <blockquote> <b>6.5.2.2 Function calls</b><br> ...<br> 10 There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call. Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function.<sup>94)</sup><br> ...<br> 94) In other words, function executions do not ‘‘interleave’’ with each other. </blockquote> <p>C++:</p> <blockquote> <b>5.2.2 Function call</b><br> ...<br> 8 The order of evaluation of arguments is unspecified. All side effects of argument expression evaluations take effect before the function is entered. The order of evaluation of the postfix expression and the argument expression list is unspecified. </blockquote> <p>Neither standard mandates the use of the hardware stack for passing function parameters; that's an implementation detail. The C++ standard uses the term "unwinding the stack" to describe calling destructors for automatically created objects on the path from a <code>try</code> block to a <em>throw-expression</em>, but that's it. Most popular architectures <em>do</em> pass parameters via a hardware stack, but it's not universal. </p> <p>[<em>Edit</em>]</p> <blockquote> <p>I am getting confusing information from the books.</p> </blockquote> <p>This is not in the least surprising, since easily 90% of books written about C are simply <em>crap</em>. </p> <p>While the language standard isn't a great resource for <em>learning</em> either C or C++, it's good to have handy for questions like this. The official&trade; standards documents cost real money, but there are drafts that are freely available online, and should be good enough for most purposes.</p> <p>The latest C99 draft (with updates since original publication) is available <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf" rel="noreferrer">here</a>. The latest pre-publication C11 draft (which was officially ratified last year) is available <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1539.pdf" rel="noreferrer">here</a>. And a publicly availble draft of the C++ language is available <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf" rel="noreferrer">here</a>, although it has an explicit disclaimer that some of the information is incomplete or incorrect.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload