printf() print arguments in reversed order
Jonathan Wakely
jwakely.gcc@gmail.com
Thu Dec 8 10:01:00 GMT 2016
On 8 December 2016 at 07:13, lhmouse wrote:
> It is undefined behavior.
>
> The evaluation of three parameters in question is (at the moment) unsequenced.
> Since each of them contains a function call, the three function calls are also
> unsequenced. The modify-and-read operations inside the function calls are
> unsequenced relative to each other. Hence the UB.
No, that's incorrect. The functions don't interleave. It's unspecified
which order they execute in, but there is no undefined behaviour.
The C++ standard says:
"For each function invocation F, for every evaluation A that occurs
within F and every evaluation B that does not
occur within F but is evaluated on the same thread and as part of the
same signal handler (if any), either A is
sequenced before B or B is sequenced before A."
So they're not unsequenced.
More information about the Gcc-help
mailing list