www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2312] New: unexpected function addresses dump behaviour

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

           Summary: unexpected function addresses dump behaviour
           Product: D
           Version: 1.034
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: enzo.petrelli fastwebnet.it


/***************************
        OS:                                     Vista SP1
        Compiler/linker:        Digital Mars D Compiler v1.034
        Tango/tangobos Lib:     tango-0.99.7-bin-win32-dmd.1.033
        Compiled with:          no compile/link flag

        During a test session where the dump of function addresses was
required,
        an unexpected result was shown, as in the following simplified test
code.

        The expected result was to see three equal series of three different
addresses.

        It should also be noted that the requested padding with '0's for hex
values in
        writefln does not work for void*

 ***************************/

import std.cstream;

class DClass
{
        void func1()
        {
                return;
        }
        void func2()
        {
                return;
        }
        void func3()
        {
                return;
        }
}

void main()
{
        DClass oObj = new DClass;
        std.cstream.dout.writefln("      object: 0x%08X", cast(void*) &oObj);
        std.cstream.dout.writefln();

        // case 1:
        std.cstream.dout.writefln("object.func1: 0x%08X", cast(void*)
&oObj.func1);
        std.cstream.dout.writefln("object.func2: 0x%08X", cast(void*)
&oObj.func2);
        std.cstream.dout.writefln("object.func3: 0x%08X", cast(void*)
&oObj.func3);

        // case 2:
        alias void delegate()   DlgPtr;
        DlgPtr pDlg = &oObj.func1;
        std.cstream.dout.writefln("object.pfunc1:0x%08X", cast(void*) pDlg);
        pDlg = &oObj.func2;
        std.cstream.dout.writefln("object.pfunc2:0x%08X", cast(void*) pDlg);
        pDlg = &oObj.func3;
        std.cstream.dout.writefln("object.pfunc3:0x%08X", cast(void*) pDlg);

        // case 3:
        alias void function()   FncPtr;
        FncPtr pFnc = cast(FncPtr) &oObj.func1;
        std.cstream.dout.writefln("object.pfunc1:0x%08X", cast(void*) pFnc);
        pFnc = cast(FncPtr) &oObj.func2;
        std.cstream.dout.writefln("object.pfunc2:0x%08X", cast(void*) pFnc);
        pFnc = cast(FncPtr) &oObj.func3;
        std.cstream.dout.writefln("object.pfunc3:0x%08X", cast(void*) pFnc);
}

/*
output obtained:

      object: 0x  12FE38

object.func1: 0x 19D3FF0
object.func2: 0x 19D3FF0
object.func3: 0x 19D3FF0
object.pfunc1:0x 19D3FF0
object.pfunc2:0x 19D3FF0
object.pfunc3:0x 19D3FF0
object.pfunc1:0x  402010
object.pfunc2:0x  402018
object.pfunc3:0x  402020
*/


-- 
Aug 25 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2312





------- Comment #1 from bugzilla digitalmars.com  2008-08-26 01:18 -------
Taking the address of a member function results in a delegate. Casting the
delegate to a void* gives the value of the 'this' part of the delegate, which
is oObj in the example, and always the same value.

Casting the address of a member function directly to a function pointer gives
the address of the function, hence the 3 different values in the last group.

The hex formatting is still an issue, though.


-- 
Aug 25 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2312


bugzilla digitalmars.com changed:

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




------- Comment #2 from bugzilla digitalmars.com  2008-08-26 01:24 -------
writefln doesn't format exactly like printf does. To get the desired hex
result, cast to int, not void*.


-- 
Aug 25 2008