readdm@walt.cc.utexas.edu (David M. Read) (10/18/89)
I am trying to write a variable-length arg-list processor in Turbo-C, and for special reasons I can't use the stuff supplied in <stdarg.h>. Everything works fine, except when I try to pass floats. I noticed that when I use va_arg (va_list, type) with type = float, the result is useless, but using type = double seems to resolve the problem. This indicates that floats are pushed onto the stack as type double, no? The trick is this: I need to BUILD a va_list, not analyze one. Can anyone tell me if my guess is correct, and perhaps how to build a va_list if it's not? Thanks in advance. ---------------------------------------------------------------------------- David M. Read best -=> readdm@walt.cc.utexas.edu all-else-fails -=> read@physics.utexas.edu "...[he's] stupid and he's ignorant but he's got guts...and guts is enough!" ----------------------------------------------------------------------------
kremer@cs.odu.edu (Lloyd Kremer) (10/18/89)
In article <19724@ut-emx.UUCP> readdm@walt.cc.utexas.edu (David M. Read) writes: >I noticed that when I use va_arg (va_list, type) with >type = float, the result is useless, but using type = double seems >to resolve the problem. This indicates that floats are pushed onto >the stack as type double, no? Traditionally, yes. In classic C, floats are promoted to doubles at any evaluation, including evaluation for the purpose of passing as an argument. In ANSI C, you can arrange for a passed float to be received as a float rather than as a double by defining the receiving function as void rec_func(float foo) /* new style definition */ { } instead of void rec_func(foo) /* old style definition */ double foo; { } -- Lloyd Kremer ...!uunet!xanth!kremer Have terminal...will hack!
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/19/89)
In article <19724@ut-emx.UUCP> readdm@walt.cc.utexas.edu (David M. Read) writes: >I am trying to write a variable-length arg-list processor in >Turbo-C, and for special reasons I can't use the stuff supplied >in <stdarg.h>. It would be interesting to hear why, since that's the only official way to get at variadic arguments. >This indicates that floats are pushed onto the stack as type double, no? Variadic arguments always have the default argument promotions applied, so yes, a float argument appears as a double to va_arg(). >The trick is this: I need to BUILD a va_list, not analyze one. The only official way to build a variadic argument list is to invoke a function whose type was declared using the ,...) notation. If you devise some other kludge, it is subject to breakage without notice in future compiler releases, or when porting to another implementation.