: From man pages in unix it seem the behavior in below usage of
rintf() is undefined.
That depends on what you mean by 'undefined'. The order of processing
parameters for a function call is not mandated by the standard, but
it is mandated that the parameters be processed "as if by
assignment" before the routine itself is invoked.
The behaviour is thus just the usual behaviour in the presence of
side-effects: they can occur in any order, and in some instances
may occur varying numbers of times.
:But, is there something to be noted from the
utput of the below line.
: printf("%d %d", i = printf("order of printing"),j = printf("Test"));
:Output:
:Testorder of printing174,
Yes, one can learn that something is broken:
- The printf format has a space between the two %d's, but the output
shown does not
- There is no comma in the output formats, but there is one in
the output shown; it should not have occured
Other than that, one could tentative figure that the in the absence
of optimization reasons otherwise, parameters are probably processed
from right to left. There is correlation with right to left processing
and implimentations that push each parameter value onto a stack
before making the call -- as contrasted with implimentations that
allocate an amount of storage large enough to hold all the parameters
(their types are all known, so the total storage can be computed)
and then store the parameters at offsets from the beginning of the
block (which tend to use left-to-right calling so as to write the
parameter values into increasing storage with incrementing stack pointer.)
Push-onto-the stack implimentations are also correlated to
ABIs in which the stack grows upwards rather than downwards.
But all of these are tentative and usually of interest only when doing
implimentation-dependant (non-portable) interfacing with non-C routines.
Though one might want to know the direction the stack grows in order
to know whether the overall program memory layout is suitable...
which would depend upon the ABI.