Jump to page: 1 2
Thread overview
offsetof
Aug 21, 2008
Heinz Traub
Aug 21, 2008
Heinz Traub
Aug 21, 2008
Heinz Traub
Nov 08, 2008
Tim M
Nov 08, 2008
Tim M
August 21, 2008
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
August 21, 2008
"Heinz Traub" wrote
> 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.

This code compiles:

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

int main(char[][] args)
{
    switch(args.length) // just to have a non-constant integer
    {
    case DIMOUSESTATE.lX.offsetof:
        break;
    }
}

This does not:

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

class Mouse
{
    this(int i)
    {
        switch(i)
        {
        case DIMOUSESTATE.lX.offsetof:
            break;
        }
    }
}

With a similar error as what you said originally.

I think this is a bug in DMD.  You should file a bug report: http://d.puremagic.com/issues/enter_bug.cgi?product=D

I can't think of a sensible workaround (besides saving the offsets in a static function, then using those in the member function).

-Steve


August 21, 2008
"Heinz Traub" <malagana15@yahoo.es> wrote in message news:g8kft9$62$1@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.


August 21, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:g8kh8p$6c4$1@digitalmars.com...

> 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.
>

I take that back, it used to be this way but something seems to have changed.


August 21, 2008
Jarrett Billingsley Wrote:

> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:g8kh8p$6c4$1@digitalmars.com...
> 
> > 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.
> >
> 
> I take that back, it used to be this way but something seems to have changed.
> 
> 

Yes sir, it used to be this way. I also checked it in your engine (nonagon).
August 21, 2008
Steven Schveighoffer Wrote:

> "Heinz Traub" wrote
> > 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.
> 
> This code compiles:
> 
> module dinputd;
> struct DIMOUSESTATE
> {
>     long lX;
>     long lY;
>     long lZ;
>     byte rgbButtons[4];
> }
> 
> int main(char[][] args)
> {
>     switch(args.length) // just to have a non-constant integer
>     {
>     case DIMOUSESTATE.lX.offsetof:
>         break;
>     }
> }
> 
> This does not:
> 
> module dinputd;
> struct DIMOUSESTATE
> {
>     long lX;
>     long lY;
>     long lZ;
>     byte rgbButtons[4];
> }
> 
> class Mouse
> {
>     this(int i)
>     {
>         switch(i)
>         {
>         case DIMOUSESTATE.lX.offsetof:
>             break;
>         }
>     }
> }
> 
> With a similar error as what you said originally.
> 
> I think this is a bug in DMD.  You should file a bug report: http://d.puremagic.com/issues/enter_bug.cgi?product=D
> 
> I can't think of a sensible workaround (besides saving the offsets in a static function, then using those in the member function).
> 
> -Steve
> 
> 

Thanks 4 your post, i'll report this bug.
I'm using dmd 1.030 for your knowledge.
August 21, 2008
"Heinz Traub" <malagana15@yahoo.es> wrote in message news:g8kivv$b19$1@digitalmars.com...
> Jarrett Billingsley Wrote:
>
>> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:g8kh8p$6c4$1@digitalmars.com...
>>
>> > 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.
>> >
>>
>> I take that back, it used to be this way but something seems to have changed.
>>
>>
>
> Yes sir, it used to be this way. I also checked it in your engine (nonagon).

Well how about that!  I couldn't help but think DIMOUSESTATE sounded familiar.


November 08, 2008
Did you find a sollution? I need to get the offset of a member of a struct so I can port a .h to a .di but dmd complains that the member doesn't exist on the struct. I dont think anyone has ever tried the code at: http://www.digitalmars.com/d/1.0/ctod.html#fieldoffset

On Fri, 22 Aug 2008 10:25:05 +1200, Jarrett Billingsley <kb3ctd2@yahoo.com> wrote:

> "Heinz Traub" <malagana15@yahoo.es> wrote in message
> news:g8kivv$b19$1@digitalmars.com...
>> Jarrett Billingsley Wrote:
>>
>>> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message
>>> news:g8kh8p$6c4$1@digitalmars.com...
>>>
>>> > 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.
>>> >
>>>
>>> I take that back, it used to be this way but something seems to have
>>> changed.
>>>
>>>
>>
>> Yes sir, it used to be this way. I also checked it in your engine
>> (nonagon).
>
> Well how about that!  I couldn't help but think DIMOUSESTATE sounded
> familiar.
>
>

November 08, 2008
On Fri, Nov 7, 2008 at 8:59 PM, Tim M <a@b.com> wrote:
> Did you find a sollution? I need to get the offset of a member of a struct so I can port a .h to a .di but dmd complains that the member doesn't exist on the struct. I dont think anyone has ever tried the code at: http://www.digitalmars.com/d/1.0/ctod.html#fieldoffset
>

Ehh, that code works with DMD 1.036, dude.  What compiler are you using?
November 08, 2008
I tried 1.036 and had the same problem. I'm using the offsetof and sizeof in a few constants which I've defined at the beginning of the file so I tried moving to the end of the file and it is no longer in error. I read somewhere that you don't have to forward declare everything in D like you do in C and also dmd wasn't reporting any undefined type errors,  just that the property didn't exist on it. Possible a bug?

On Sat, 08 Nov 2008 16:03:08 +1300, Jarrett Billingsley <jarrett.billingsley@gmail.com> wrote:

> On Fri, Nov 7, 2008 at 8:59 PM, Tim M <a@b.com> wrote:
>> Did you find a sollution? I need to get the offset of a member of a struct
>> so I can port a .h to a .di but dmd complains that the member doesn't exist
>> on the struct. I dont think anyone has ever tried the code at:
>> http://www.digitalmars.com/d/1.0/ctod.html#fieldoffset
>>
>
> Ehh, that code works with DMD 1.036, dude.  What compiler are you using?

« First   ‹ Prev
1 2