Thread overview
offsetof: Bug or Documentation Error?
Oct 31, 2005
Garett Bass
Nov 01, 2005
Bruno Medeiros
Nov 01, 2005
Oskar Linde
Nov 01, 2005
Bruno Medeiros
October 31, 2005
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}


November 01, 2005
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."
November 01, 2005
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


November 01, 2005
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."