This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: printf() print arguments in reversed order
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: lhmouse <lh_mouse at 126 dot com>
- Cc: topher <topherchen at gmail dot com>, gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 8 Dec 2016 10:01:30 +0000
- Subject: Re: printf() print arguments in reversed order
- Authentication-results: sourceware.org; auth=none
- References: <CAGY91ju-B83eewM1ZzAcJw2fK=ct7aTsgdmFeBNLXzcHH=rRCw@mail.gmail.com> <42eefa54.1e7314.158dd47a8e7.Coremail.lh_mouse@126.com>
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.