RE: [GD-Windows] Compiler code gen
Brought to you by:
vexxed72
From: Jon W. <hp...@mi...> - 2004-11-29 17:20:33
|
> After much looking at the code I can see that floats passed to variadic > functions are having 8 bytes pushed onto the stack instead of 4 bytes. If I > call a non-variadic function only 4 bytes are used. Is this considered > correct behavior for Windows? I believe this is type promotion, as defined by the C/C++ language. You should get the float arguments back out using va_arg(double). Sadly, the C++ standards document just punts to the C standard document, so I can't give you a definitive reference. This program shows how it works (note: func2 is correct, func1 is incorrect): #include <stdarg.h> #include <stdio.h> void func1( int a, ... ) { va_list vl; va_start( vl, a ); float f1 = va_arg( vl, float ); float f2 = va_arg( vl, float ); printf( "%f %f\n", f1, f2 ); } void func2( int a, ... ) { va_list vl; va_start( vl, a ); float f1 = va_arg( vl, double ); float f2 = va_arg( vl, double ); printf( "%f %f\n", f1, f2 ); } int main() { func1( 1, 2.0f, 3.0f ); func2( 1, 2.0f, 3.0f ); return 0; } Cheers, / h+ |