www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - offsetof bug

reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
class Foo {
  int x;
}
void main() {
  Foo.x.offsetof;
}

gives
C:\d>dmd off.d
off.d(5): 'this' is only allowed in non-static member functions
off.d(5): this for x needs to be type Foo not type int 
Jul 04 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message 
news:dac0ps$1hh4$1 digitaldaemon.com...
 off.d(5): 'this' is only allowed in non-static member functions
 off.d(5): this for x needs to be type Foo not type int

Might have to do with the fact that class members are free to be rearranged by the compiler. The compiler may not know the offsets of the members until a later phase.
Jul 04 2005
parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:dac313$1jcg$1 digitaldaemon.com...
 "Ben Hinkle" <ben.hinkle gmail.com> wrote in message 
 news:dac0ps$1hh4$1 digitaldaemon.com...
 off.d(5): 'this' is only allowed in non-static member functions
 off.d(5): this for x needs to be type Foo not type int

Might have to do with the fact that class members are free to be rearranged by the compiler. The compiler may not know the offsets of the members until a later phase.

The posted example is pretty much the same as the one from the doc (see the Classes page about Field properties). I haven't gotten offsetof to work.
Jul 04 2005
parent reply "Uwe Salomon" <post uwesalomon.de> writes:
On Mon, 04 Jul 2005 21:53:57 +0200, Ben Hinkle <bhinkle mathworks.com>  
wrote:

 "Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message
 news:dac313$1jcg$1 digitaldaemon.com...
 "Ben Hinkle" <ben.hinkle gmail.com> wrote in message
 news:dac0ps$1hh4$1 digitaldaemon.com...
 off.d(5): 'this' is only allowed in non-static member functions
 off.d(5): this for x needs to be type Foo not type int

Might have to do with the fact that class members are free to be rearranged by the compiler. The compiler may not know the offsets of the members until a later phase.

The posted example is pretty much the same as the one from the doc (see the Classes page about Field properties). I haven't gotten offsetof to work.

Please read my post in digitalmars.D. "Ben Hinkle" in the subject :) Ciao uwe
Jul 04 2005
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Uwe Salomon" <post uwesalomon.de> wrote in message 
news:op.stem8xwn6yjbe6 sandmann.maerchenwald.net...
 On Mon, 04 Jul 2005 21:53:57 +0200, Ben Hinkle <bhinkle mathworks.com> 
 wrote:

 "Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message
 news:dac313$1jcg$1 digitaldaemon.com...
 "Ben Hinkle" <ben.hinkle gmail.com> wrote in message
 news:dac0ps$1hh4$1 digitaldaemon.com...
 off.d(5): 'this' is only allowed in non-static member functions
 off.d(5): this for x needs to be type Foo not type int

Might have to do with the fact that class members are free to be rearranged by the compiler. The compiler may not know the offsets of the members until a later phase.

The posted example is pretty much the same as the one from the doc (see the Classes page about Field properties). I haven't gotten offsetof to work.

Please read my post in digitalmars.D. "Ben Hinkle" in the subject :) Ciao uwe

got it - thanks!
Jul 04 2005