|
|
On Fri, 28 Mar 2008 20:43:45 UTC, CBFalconer <cbfalconer@xxxxxxxxx>
wrote:
> Ioannis Vranos wrote:
> >
> ... snip ...
> >
> > int main(void) {
> > int x= 1;
> > somefunc( (x++, somefunc(x)) );
> > return 0;
> > }
> >
> > In the above, the expression (x++, somefunc(x)) is evaluated to 2,
> > so I assume it is guaranteed that it will print "2".
>
> Because that is using the comma operator. However:
Here is no comma operator in sight. The comma here is only a parameter
separator. There are 3 squence pointa:
1. immediately bofre inner somefunc is called
2. immediately before outer somefunc is called
3. when the ';' is reached.
It is undefined when the ++ gets evaluated
- before inner somefunc gets called
- after inner somefunc gets called
- before the parameter of the inner somefunc gets evaluated
- after the parameter of the inner somefunc gets evaluated
> somefunc(int x, int y) {printf("%d\n", x);}
>
> int main(void) {
> int x = 1;
> somefunct(x++, x);
> return 0;
> }
>
> has no idea whether x++ is executed before or after the x parameter
> load. That's why it is illegal.
>
It is clearly defined that the original value of x is used as the
value of the first parameter. It is clearly undefined which value the
second parameter will become when somefunc() gets executed.
--
Tschau/Bye
Herbert
Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
|
|