www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Issue 1543] New: Error boxing floats

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543

           Summary: Error boxing floats
           Product: DGCC aka GDC
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn users.sf.net
        ReportedBy: mariusmuja gmail.com


The following program outputs 0 instead of the correct value (95):

import std.stdio;
import std.boxer;

void main(char[][] args)
{
        float a = 95.0f;
        Box b = box(a);

        writefln(b);
}

I have tested it with the latest svn version of gdc and it doesn't work
rorrectly. It outputs the correct value when compiled with dmd.


-- 
Oct 01 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543


mariusmuja gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mariusmuja gmail.com,
                   |                            |alan akbkhome.com
            Summary|Error boxing floats         |Incorrect passing of floats
                   |                            |to variadic functions




------- Comment #1 from mariusmuja gmail.com  2007-10-13 02:16 -------
The error seems to be from the fact that gdc doesn't pass correctly float
arguments to variadic functions. In the following example the function foo_d()
prints the expected value, but the function foo() doesn't.

import std.stdio;

void foo(...)
{   
        writefln(*cast(float*)_argptr);
}

void foo_d( ...)
{   
        writefln(*cast(double*)_argptr);
}

void main()
{
        foo(10.1f);
        foo_d(10.1);
}


-- 
Oct 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543





------- Comment #2 from afb algonet.se  2007-10-13 02:40 -------

Seems to be working here, if you avoid the unportable casts...

import std.stdio;
import std.stdarg;

void foo(...)
{   
        writefln(va_arg!(float)(_argptr));
}

void foo_d( ...)
{   
        writefln(va_arg!(double)(_argptr));
}

void main()
{
        foo(10.1f);
        foo_d(10.1);
}


-- 
Oct 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543


mariusmuja gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|glue layer                  |Phobos
            Summary|Incorrect passing of floats |std.boxer broken for gdc
                   |to variadic functions       |(was: Incorrect passing of
                   |                            |floats to variadic
                   |                            |functions)




------- Comment #3 from mariusmuja gmail.com  2007-10-13 03:57 -------
I didn't know about va_arg!()(). It seems then that std.boxer is broken for
gdc, since it uses the unportable casts and assumes _argptr is of type void*,
which by looking at std.stdarg it not necessarily true. 


-- 
Oct 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543





------- Comment #4 from afb algonet.se  2007-10-13 04:12 -------
I think that's a known issue, since std.boxer says: "This module make not work
on all GCC targets due to assumptions about the type of va_list."


-- 
Oct 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543


dvdfrdmn users.sf.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #5 from dvdfrdmn users.sf.net  2007-10-13 16:46 -------
Fixed this particular problem on targets for which std.boxer already works. 
Also fixed for 1- and 2-bit integral types.  Fix is in SVN rev 183 / release
0.25.


-- 
Oct 13 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1543





------- Comment #6 from dvdfrdmn users.sf.net  2007-10-13 19:46 -------
sigh... make that svn rev 184


-- 
Oct 13 2007