Q47985: Calling Order Undefined – Function Calls in Single Expression

Article: Q47985
Product(s): See article
Version(s): 5.00 5.10 | 5.00 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | S_QuickC S_QuickASM | mspl13_c
Last Modified: 15-JAN-1990

When C evaluates more than one function call in a single expression,
the calls usually are made in reversed or arbitrary order, rather than
in the stated order. Since there is no defined precedence in C for the
order in which multiple function calls are made within a single
expression, the result is compiler-dependent. In Microsoft's products,
these functions are usually evaluated from right to left.

This occurs in C Versions 5.00 and 5.10 and in QuickC Versions 1.01,
2.00, and 2.01.

The following code demonstrates this:

void main( void )
{
   printf( "First: %d Second: %d", getch(), getch() );
}

When this code is compiled and run, it returns first the second
keyboard code that is scanned. For example, if the F5 key is pressed,
returning first a null character followed by its extended code, the
program returns "First: 63 Second: 0." The null character that is
generated by the keyboard first, is written second.