The information in this article applies to:
SYMPTOMSWhen the va_arg() macro is used more than once in a function parameter list, an application produces different results depending on the version of the C compiler used to build the application. CAUSEThe C standard does not precisely define expression evaluation order. In many cases, the compiler implementation determines the order in which an application evaluates expressions. RESOLUTIONTo preserve the original order of the arguments, use the va_arg() macro only once in a given expression. One method is to evaluate the expression in a loop that processes each variable argument and stops when the last parameter is reached. MORE INFORMATION
The va_arg() macro provides a method to access the arguments of a function
when the function can accept a variable number of arguments. The macro
returns a variable parameter by incrementing the value of the arg_ptr that
points to the list of arguments. The values returned depend on the order in
which the application evaluates the va_arg() macros.
Sample Code #1
When this sample is compiled with C version 5.1 or C/C++ version 8.0 for MS-
DOS, the sample produces the following output:
However, when this sample is compiled with Microsoft C versions 6.0, 6.0a,
6.0ax, Microsoft C/C++ version 7.0, or Microsoft Visual C++ 32-bit Edition,
versions 1.0 through 4.2, the sample produces the following output:
With Microsoft Visual C++, 32-bit Edition, version 5.0, the output is the
same as C 5.1 and C/C++ 8.0.
In the following sample code, the expressions are evaluated correctly without regard to the expression evaluation order. Sample Code #2
The output is as follows:
Additional query words:
Keywords : kbCRT kbVC100 kbVC150 kbVC200 kbVC210 kbVC400 kbVC410 kbVC420 kbVC500 kbVC600 |
Last Reviewed: July 1, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |