KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

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.

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.