RE: Compiler code gen

"Jon Watte" <[email protected]> Mon, 29 Nov 2004 09:20:37 -0800
Newsgroups gmane.games.devel.windows
Message-ID <[email protected]>
> 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+



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555