Thread overview
Access Violation (call to address 0x00000000)
Feb 22, 2004
Kris
Feb 23, 2004
Walter
Feb 23, 2004
Kris
Feb 23, 2004
Kris
February 22, 2004
Is this a known bug?

************************************
class Foo
{
public:
      void bar();             // no body (and no 'abstract' decoration)
                                   // should generate a compile-time error,
right?
}

int main(char [][] args)
{
    Foo foo = new Foo();  // compiler thinks Foo is a concrete class
    foo.bar();                     // call to address 0x00000000
    return 0;
}

************************************
Assembly listing:

28:              Foo foo = new Foo();
00402014   push        offset __Class_5hello3Foo (0040e08c)
00402019   call          __d_newclass (00402140)
0040201E   mov        dword ptr [foo],eax
29:              foo.bar();
00402021   mov        ecx,dword ptr [eax]
00402023   call         dword ptr [ecx+18h]


ecx points to the vTable:
0040E0C8  0040E08C  00402248  0040225C
00402268   0040226C  00402274  00000000

- Object.print(), toString(), toHash(), opCmp(), opEquals()
are represented by addrs 00402248 thru 00402274

- Foo.bar() follows thereafter, with addr 00000000


February 23, 2004
It's not a bug. That is there for the case where the class definition (and vtbl[]) is supplied in some other .obj file, for example, if you're shipping a library.


February 23, 2004
Thanks Walter;

Still, shouldn't the linker have barfed on it? This quietly produces what is effectively a bogus executable, from what was originally a typo <g>  ...  it that not an issue, yet?

- Kris


"Walter" <walter@digitalmars.com> wrote in message news:c1djo6$2k7a$1@digitaldaemon.com...
> It's not a bug. That is there for the case where the class definition (and vtbl[]) is supplied in some other .obj file, for example, if you're
shipping
> a library.
>
>


February 23, 2004
I guess I'm really confused on this one Walter. If I simply declare a method within a class (sans method body), it's expected to be resolved externally (presumeably within the external class) but the Linker doesn't complain and the executable fails:

class Foo
{
        void add();
}

void main()
{
  Foo foo = new Foo();
  foo.add();          // access violation
}

If, however, I introduce an interface like so:

interface Wumpus
{
        void add();
}

class Foo : Wumpus
{
        void add();
}

void main()
{
  Foo foo = new Foo();
  foo.add();
}

Now the Linker *does* complain that it can't resolve add():   Error 42: Symbol Undefined _D5hello3Foo3addFZv.

If this does not identify some kind of bug, then I'm having a hard time grokking the semantics. Could you help me understand, please?

- Kris


"Walter" <walter@digitalmars.com> wrote in message news:c1djo6$2k7a$1@digitaldaemon.com...
> It's not a bug. That is there for the case where the class definition (and vtbl[]) is supplied in some other .obj file, for example, if you're
shipping
> a library.
>
>