www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - offsetof: Bug or Documentation Error?

reply "Garett Bass" <garettbass studiotekne.com> writes:
I found an inconsistency in the D Documentation.  In class.html, under the 
heading "Field Properties" there is an example:

class Foo
{
    int x;
}
...
void test(Foo foo)
{
    size_t o;

    o = Foo.x.offsetof;   // yields 8
    o = foo.x.offsetof;   // error, .offsetof an int type
}My own test code contradicts this, note that the error condition is 
opposite the example:class Foo {    int x;}int main() {    Foo foo = new 
Foo;    size_t o;    o = Foo.x.offsetof; // error: 'this' is only allowed in 
non-static                        //         member functions 
// error: this for x needs to be type Foo not                        // 
type int    o = foo.x.offsetof; // yields 8} 
Oct 31 2005
parent reply Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Garett Bass wrote:
 I found an inconsistency in the D Documentation.  In class.html, under the 
 heading "Field Properties" there is an example:
 
 class Foo
 {
     int x;
 }
 ....
 void test(Foo foo)
 {
     size_t o;
 
     o = Foo.x.offsetof;   // yields 8
     o = foo.x.offsetof;   // error, .offsetof an int type
 }My own test code contradicts this, note that the error condition is 
 opposite the example:class Foo {    int x;}int main() {    Foo foo = new 
 Foo;    size_t o;    o = Foo.x.offsetof; // error: 'this' is only allowed in 
 non-static                        //         member functions 
 // error: this for x needs to be type Foo not                        // 
 type int    o = foo.x.offsetof; // yields 8} 
 
 
Starting to seem like a bug to me. The following code: class Foo { int x; } int main(char[][] args) { Foo foo = new Foo(); foo.x.offsetof; } gives a runtime assert error after main: Error: AssertError Failure test.d(11) -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Nov 01 2005
parent reply Oskar Linde <Oskar_member pathlink.com> writes:
In article <dk7eo0$2qji$1 digitaldaemon.com>, Bruno Medeiros says...
Starting to seem like a bug to me. The following code:

   class Foo
   {
     int x;
   }

   int main(char[][] args)
   {
     Foo foo = new Foo();
     foo.x.offsetof;
   }

gives a runtime assert error after main:
   Error: AssertError Failure test.d(11)
Thats your main() not returning... A better error message would be appreciated. /Oskar
Nov 01 2005
parent Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Oskar Linde wrote:
 In article <dk7eo0$2qji$1 digitaldaemon.com>, Bruno Medeiros says...
 
Starting to seem like a bug to me. The following code:

  class Foo
  {
    int x;
  }

  int main(char[][] args)
  {
    Foo foo = new Foo();
    foo.x.offsetof;
  }

gives a runtime assert error after main:
  Error: AssertError Failure test.d(11)
Thats your main() not returning... A better error message would be appreciated. /Oskar
Whoops, my bad :( . I've been using the same test source file all this time (which incindently has a return from main) that I never noticed that. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Nov 01 2005