[Issue 2302] offsetof property not working properly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 27 11:39:55 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2302





------- Comment #2 from malagana15 at yahoo.es  2008-08-27 13:39 -------
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];
}


-- 



More information about the Digitalmars-d-bugs mailing list