floats passed as doubles?

Started by
4 comments, last by wasd 20 years, 2 months ago
I''m writing a console plug in, and I''m using the va_arg macros to access variable argument lists passed to the print() function. The thing is, if I pass the function a float, it actually passes it to the function using 8 bytes instead of 4, which indicates it''s passing it as a double. Is this normal? Currently I''m having to retrieve the value as a double, then cast it to a float. --------------------------------------- Let''s struggle for our dream of Game! http://andrewporritt.4t.com
Advertisement
how are u passing that float?

void func(float);

like this:
float a;
func(a)

or like this:
func(12.65);

not sure if this will help, but try adding "f" at the end of the number...
func(12.65f);
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
g_Console.Print("hello2\n%.10f %.2f %.2f\n", 0.0025f, 0.000005f, -20000000.0f);

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com
and how do u know that it''s passing 8 bytes?
just wondering
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
Yes it''s normal.

MSDN

Variable Argument Lists
Function declarations in which the last member of argument-declaration-list is the ellipsis (...) can take a variable number of arguments. In these cases, C++ provides type checking only for the explicitly declared arguments. You can use variable argument lists when you need to make a function so general that even the number and types of arguments can vary. The printf family of functions is an example of functions that use variable argument lists.

To access arguments after those declared, use the macros contained in the standard include file STDARG.H as described in Functions with Variable Argument Lists.

Microsoft Specific

Microsoft C++ allows the ellipsis to be specified as an argument if the ellipsis is the first argument and the ellipsis is preceded by a comma. Therefore, the declaration int Func( int i, ... ); is legal, but int Func( int i ... ); is not.

END Microsoft Specific

Declaration of a function that takes a variable number of arguments requires at least one “placeholder” argument, even if it is not used. If this place-holder argument is not supplied, there is no way to access the remaining arguments.

When arguments of type char are passed as variable arguments, they are converted to type int. Similarly, when arguments of type float are passed as variable arguments, they are converted to type double. Arguments of other types are subject to the usual integral and floating-point promotions. See Integral Promotions in Chapter 3 for more information.
Doh! Case of RTFM there, sorry.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

This topic is closed to new replies.

Advertisement