www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 807] New: inout params don't mesh with fpu

reply d-bugmail puremagic.com writes:

           Summary: inout params don't mesh with fpu
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: default_357-line yahoo.de


When putting inout real parameters directly on the floating point stack, doing
stuff and popping them back, for some reason the parameter doesn't get changed.
Verified on win32/mingw-gdc0.21svn and linux/dmd1.0

Update (5 minutes later)
This is beyond odd. I've got an inout variable changing addresses.
Replace the test function in the paste with
void test(inout real r) {
  version(Tango) (new DisplayWriter(Cout))("Before: r is
  else writefln("Before: r is ")(cast(void*)(&r));
  asm { fld r; fsin; fstp r; }
  version(Tango) (new DisplayWriter(Cout))("After: r is
  else writefln("After: r is ")(cast(void*)(&r));
I got the following output: "Before: r is <someaddress>"  "After: r is 0"
Please enlighten me.

Jan 06 2007
parent d-bugmail puremagic.com writes:

bugzilla digitalmars.com changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID

------- Comment #1 from bugzilla digitalmars.com  2007-02-02 03:16 -------
inout parameters are passed by reference, i.e. they are actually a pointer. The
sample code is using inline assembler, referencing the inout parameter. So, the
inline assembler:

    void foo(inout real r)
        {   fld r;

is actually loading a *pointer* and treating it as if it were a real.

Inline assembler does exactly what you tell it to do. To make the above work,
use instead:
            mov EAX,r ;
            fld real ptr [EAX] ;

Not a compiler bug.

Feb 02 2007