offsetof

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Aug 21 12:56:10 PDT 2008


"Heinz Traub" <malagana15 at yahoo.es> wrote in message 
news:g8kft9$62$1 at digitalmars.com...
> Hi,
>
> I've been doing Direct Input code and need to port C to D. I'm trying to 
> get the offset of a struct member 
> (http://www.digitalmars.com/d/1.0/ctod.html#fieldoffset) but when i do 
> this:
>
> module dinputd;
> struct DIMOUSESTATE
> {
> long lX;
> long lY;
> long lZ;
> byte rgbButtons[4];
> }
>
> ...
> module dinputdriver;
> case DIMOUSESTATE.lX.offsetof:
>
> I get the following error:
>
> Error: this for lX needs to be type DIMOUSESTATE not type 
> dinputdriver.Mouse.
>
> if i call offsetof in dinputd(the same module where DIMOUSESTATE struct is 
> declared) i get the following error:
>
> dinputd.d(89): Error: no property 'lX' for type 'DIMOUSESTATE'
>
> Damn! i'm doing everything as specified by the docs. But i can't get it to 
> work.
>
> Can someone help me please. Thanks in advance.
>
> Heinz

It's actually exactly the opposite from how it's defined in the spec: you 
can only use offsetof on instances of user-defined types, not on the type 
itself.

It makes _absolutely_ no sense, I know.  I can't help but feel it's a bug, 
but it's been this way for over 4 years. 




More information about the Digitalmars-d-learn mailing list