www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2302] New: offsetof property not working properly

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

           Summary: offsetof property not working properly
           Product: D
           Version: 1.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: malagana15 yahoo.es


Please check these 2 short posts on the newsgroup. You'll notice that offsetof
property is not working the way it should or the way it is described in the
doc:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=13576

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=13579

Please reply to know it's a bug.

DMD 1.030

Thanks for your support.


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






Please note that this issue is related to offsetof for structures. Offsetof for
classes have had many bugs but have been fixed.

The thing here is that offsetof for a structure can only be called from a
static function and not from anywhere, so, porting some C code to D modules is
impossible or full of workarounds.


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






I'm posting a few workarounds to get offsetof to work on structures:

1) Create a static function to return the offset, how you do it will depend on
your code. This seems to work fine.

2) Use this template i did, it compiles ok but needs more testing, i call it
from a static enviroment and works perfect:
(This try to simulate the Win32 macro FIELD_OFFSET)

template FIELD_OFFSET(alias T)
{
        const uint FIELD_OFFSET = T.offsetof;
}

Example:

module x;

const uint DIMOFS_X = FIELD_OFFSET!(DIMOUSESTATE.lX);
const uint DIMOFS_BUTTON1 = FIELD_OFFSET!(DIMOUSESTATE.rgbButtons) + 1;

struct DIMOUSESTATE
{
        long lX;
        long lY;
        long lZ;
        byte rgbButtons[4];
}


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


Vladimir <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |thecybershadow gmail.com
         Resolution|                            |DUPLICATE





PDT ---


*** This issue has been marked as a duplicate of issue 899 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009