Page 1 of 1

PS2SDK's printf: double->float ?

Posted: Sun Sep 12, 2004 12:25 am
by pixel
After some IRC discussions, it came up that "doubles are evil for the PS2", and I think that nobody will really argue about that.

What is to argue now, is the fact that the xprintf.c code from ps2sdk internally and externally use doubles. The internal part could be changed quite quickly without too much side effect.

But the external part is the line va_arg(ap,double). Well, I have to admit I have quite no knowledge about how va_arg will work actually. I do think that it shouldn't cause any trouble, and since that it's a gcc's builtin, it should behave nicely. But I am a bit clueless, and I don't even know if my tests would be relevant.

So, before changing the doubles to float inside xprintf.c (or maybe, to be a little bit nicer, having a #define which will default to float, permitting people to change that using some CFLAGS's -D on the command line), I'd like to know if it would break things or not ? Again, I don't know if any of my tests are relevant, and I don't like the idea "let's change it, and wait for people's complains" :P

Posted: Sun Sep 12, 2004 2:51 am
by mrbrown
AFAIK you will have to hack GCC to prevent it from promoting float arguments to vararg functions to doubles.

Posted: Sun Sep 12, 2004 3:28 am
by pixel
After some hacks and code readings, I came to the same conclusion...

Now, what good of an idea would it be ? Do people think that we should definitively get rid of doubles in the __builtin_va_arg function of gcc ? Or shall I try to do that silently ?

Posted: Sun Sep 12, 2004 4:26 am
by mrbrown
IMO the best thing would be to turn it into an compiler option, e.g. -fno-promote-float-varargs or something.

Posted: Sun Sep 12, 2004 5:04 am
by pixel
Hum, yeah, but, it wouldn't be much of a safe situation ? Well, I have to investigate it a bit further...

Posted: Sun Sep 12, 2004 10:45 pm
by pixel
On a side note, I found this piece of documentation which may be of interest (not directly related to the topic, but may be of interest since I am poking stdio/stdlib lately...)
VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
corresponding to the list of fixed arguments. Then use va_arg
normally to get the variable arguments, or pass your va_list object
around. You do not declare the va_list yourself; VA_OPEN does it
for you.

Here is a complete example:

Code: Select all

        int
        printf VPARAMS ((const char *format, ...))
        {
           int result;

           VA_OPEN (ap, format);
           VA_FIXEDARG (ap, const char *, format);

           result = vfprintf (stdout, format, ap);
           VA_CLOSE (ap);

           return result;
        }