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

Re: Implementation-defined behaviour

Subject: Re: Implementation-defined behaviour
From: Richard
Date: Fri, 28 Mar 2008 18:16:13 +0100
Newsgroups: comp.lang.c

Ioannis Vranos <ivranos@xxxxxxxxxxxxxxxxxxxxxxxxx> writes:

> Dann Corbit wrote:
>> 
>> --- Module:   foo.c (C)
>>                             _
>>     printf("%d %d\n", n++, n);
>> foo.c(8) : Warning 564: variable 'n' depends on order of evaluation
>
> I wonder a bit about this one. Let's consider a simpler version:
>
>
> #include <stdio.h>
>
>
> int somefunc(int x)
> {
>       printf("%d\n", x);
>       
>       return x;
> }
>
>
> int main(void)
> {
>       int x= 1;
>       
>       somefunc(x++);  
>       
>       return 0;
> }
>
>
>
> Above, is it well defined that it will be printed "1"?

Could you explain your thinking if you thought it would be anything else?

>
>
>
> #include <stdio.h>
>
>
> int somefunc(int x)
> {
>       printf("%d\n", x);
>       
>       return x;
> }
>
>
> 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".

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