Post incrementers in arrays as function arguments

Jonas Jensen bones0_list@hotmail.com
Fri Aug 18 15:06:00 GMT 2000


> This code has produced 3 different results on 4 systems.
> The second result was on the Cygwin B20 system
> [snip]
> /* This use of var++ in a function call is
> unpredictable */
> print_array(array[i++],array[i++],array[i++]);
> }
> [snip]
> However, this works on some platforms and could become an error in porting
> software.

This is semi-documented behavior. Check out the infopage for gcc, this is
from the section "non-bugs":
>>>>>>>>>>>>>>>>>>>>>>>>>* Making side effects happen in the same order as in some other
 compiler.
 It is never safe to depend on the order of evaluation of side
 effects. For example, a function call like this may very well
 behave differently from one compiler to another:
 void func (int, int);
 int i = 2;
 func (i++, i++);
 There is no guarantee (in either the C or the C++ standard language
 definitions) that the increments will be evaluated in any
 particular order. Either increment might happen first. `func'
 might get the arguments `2, 3', or it might get `3, 2', or even
 `2, 2'.
<<<<<<<<<<<<<<<<<<<<<<<<<
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /