how can i get all the arguments in the va_list
-
If i have a function myfunc(arg1,arg2,arg3), how can i include them, all, in a va_list variable? if i use va_start(list, arg1), i won't have arg1 in the list and I cannot change the singnature of the function myfunc. If I do something like: list = (va_list)&arg1 it works for types like int, unsigned int, even char*, but not float or double. If one of the args is float, it will store in list a 0 instead of the real value. please help :~
-
If i have a function myfunc(arg1,arg2,arg3), how can i include them, all, in a va_list variable? if i use va_start(list, arg1), i won't have arg1 in the list and I cannot change the singnature of the function myfunc. If I do something like: list = (va_list)&arg1 it works for types like int, unsigned int, even char*, but not float or double. If one of the args is float, it will store in list a 0 instead of the real value. please help :~
You'd have to include a
sizeof(arg1)
to account for the stack space used byarg1
and include it. Something like this:char \* ArgPtr = (char \*)&arg1 - sizeof(arg1); if( ArgPtr == (char \*)&arg2 ) { // Stack growing the other way... ArgPtr = (char \*)&arg1 + sizeof(arg1); } list = (va\_list)ArgPtr;
That oughta take into account whatever way the stack grows. Bob Ciora
-
You'd have to include a
sizeof(arg1)
to account for the stack space used byarg1
and include it. Something like this:char \* ArgPtr = (char \*)&arg1 - sizeof(arg1); if( ArgPtr == (char \*)&arg2 ) { // Stack growing the other way... ArgPtr = (char \*)&arg1 + sizeof(arg1); } list = (va\_list)ArgPtr;
That oughta take into account whatever way the stack grows. Bob Ciora
Indeed something like that works. Thank you Now something else troubles me regarding float. I make myself a list of the arguments. the list contains a char*, a float and something. I check them, they are ok. But when i'm tring to right them into a file using vfprintf(file,format,list), instead of my float value i always get a 0.00000 This is too much :-D
-
Indeed something like that works. Thank you Now something else troubles me regarding float. I make myself a list of the arguments. the list contains a char*, a float and something. I check them, they are ok. But when i'm tring to right them into a file using vfprintf(file,format,list), instead of my float value i always get a 0.00000 This is too much :-D
-
You should always use the va_ family of functions to do this. Anyway, floats are always pushed as doubles in var arg functions. You can check some assembly listings to verify this.