In article <
1b2121ee-8668-4901...@googlegroups.com>,
<
sili...@gmail.com> wrote:
...
>I'll just put the code here as well:
>#include <stdio.h>
>
>int x = 11;
>
>int increment(){
> x += 1;
> return x;
>}
>
>int main(){
> printf("%d %d", increment(), x);
> return 0;
>}
Thank you. That helps a lot.
Anyway, the answer to your question is that, yes, the C language, as
defined by the standards documents (that which, leader Keith will tell you,
is the only thing we can discuss in this group), does not specify the order
of evaluation of function args. In fact, I think the above program
qualifies as the dreaded "undefined behavior", and we all know what that
means (*).
That said, the fact is that most Unix implementations of C (and, in fact,
most implementations of C period) use what is called the "cdecl" calling
convention, which means that things are pushed onto the "stack" (oooh!!! I
said the naughty word!!!) in right-to-left order, so that you get the
output you see. The original value of x is pushed first, then the
incremented value. The incremented value is printed first, followed by the
original value.
But, as noted, since it is "undefined behavior", anything could happen,
including spaghetti flying out of your nose. If, however, your
implementation specifies "cdecl", as many/most/all do, then you're safe.
Windows, incidentally, is "cdecl" for non-API functions, but "Pascal" for
WinAPI calls.
(*) In fact, a true pedant would point out that the fact that there is no
trailing newline in the printf() statement also generates "undefined behavior".
--
The last time a Republican cared about you, you were a fetus.