comp.lang.c
[Top] [All Lists]

Re: Implementation-defined behaviour

Subject: Re: Implementation-defined behaviour
From: CBFalconer
Date: Fri, 28 Mar 2008 15:43:45 -0500
Newsgroups: comp.lang.c

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:

 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.

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>
            Try the download section.



-- 
Posted via a free Usenet account from                                 www.teranews.com">http://www.teranews.com


<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy