Newsgroup: comp.lang.c++
Subject: How come this is undefined behavior?
From: Peter <pilarp@...>
Date: Thu, 11 Jul 2013 13:35:38 -0700 (PDT)
Section 1.9 ("Program execution") of C++11 standard introduces the following example of undefined behaviour:
for function declared as
void f(int, int);
the call:
f(i = -1, i = -1);
yields undefined behaviour.
How come? Of course I know the order in which arguments of f are evaluated is unspecified, so result of f(i, i++) would indeed be undefined, but what's wrong with f(i = -1, i = -1)? Why should the order matter here? f doesn't get called until both arguments are evaluated and both assignment expressions are independent, so what difference does it make if first and then second gets evaluated or the other way round since both evaluate to -1 anyway?
Subject: How come this is undefined behavior?
From: Peter <pilarp@...>
Date: Thu, 11 Jul 2013 13:35:38 -0700 (PDT)
Section 1.9 ("Program execution") of C++11 standard introduces the following example of undefined behaviour:
for function declared as
void f(int, int);
the call:
f(i = -1, i = -1);
yields undefined behaviour.
How come? Of course I know the order in which arguments of f are evaluated is unspecified, so result of f(i, i++) would indeed be undefined, but what's wrong with f(i = -1, i = -1)? Why should the order matter here? f doesn't get called until both arguments are evaluated and both assignment expressions are independent, so what difference does it make if first and then second gets evaluated or the other way round since both evaluate to -1 anyway?
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?40485-How-come-this-is-undefined-behavior&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment