|
|
CBFalconer <cbfalconer@xxxxxxxxx> writes:
> 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.
Please consider being more cautious with the word "illegal". The C
standard doesn't even use the word (except in a footnote referring to
an "illegal instruction").
If I were going to use the word "illegal" with respect to C code, I'd
reserve it for constructs that require a diagnostic, namely syntax
errors and constraint violations. (I'm not sure about applying it to
#error.)
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|
|