On Mon, Jan 04, 2021 at 05:50:53PM +0100, Otto Moerbeek wrote:

> tOn Mon, Jan 04, 2021 at 01:42:48PM +0100, Theo Buehler wrote:
> 
> > > > +               return log_sockaddr(addr2sa(addr, 0, &len), len);
> > > 
> > > Perhaps I haven't yet had enough coffee this year, but I'm unsure
> > > whether it is actually guaranteed that addr2sa() is called before the
> > > second len in this line is passed to log_sockaddr().
> > 
> > Answering my own question: C99 and C11 6.5.2.2.12 require that all side
> > effects must be completed before log_sockaddr() is called. As addr2sa()
> > changes the second len as a side effect, this should be fine.
> > 
> > ok tb
> > 
> 
> I am not convinced. Consider
> 
> #include <stdio.h>
> 
> char x;
> 
> char f(char *p)
> {
>         *p = 'f';
>       return 'r';
> }
> 
> int main()
> {
>       x = 'm';
>       printf("%c %c %c\n", x, f(&x), x);
> }
> 
> prints "m r f" here. The first x is not influenced by the call to
> f(), while the second is. So the side effetc only affects one of the args.
> 
>       -Otto
> 
> 

And if you compile with gcc on amd64 you'll get "f r m".

In my reading, the C standard is clear; the order of evaluation of the
arguments is undefined. The side effects should indeed take effect
before calling the function, but that's something different, e.g.
before the side effetcs are complete, some of the args may already be
on the stack,

        -Otto

Reply via email to