September 20, 2005
I like the way my code looks written in D but I need to keep my C safety net. So it is important for me to be able to use *all* my code written in D.

I have only very basic literacy in C++. So I have some questions that might be obvious to someone from a C++/OOP background.

What is the point of object.vtbl[]? It's per type info so you know everything about member functions at compile time and function names appear to show up in the object file mangled in a way that makes sense for virtual functions. Is there something dynamic happening to vtbl[]? I can imagine use in getting a pointer to an unknown object and then searching it's vtbl[] for a destructor... but there doesn't seem to be enough info available to do that.

Will the present behavior of extern(C) on classes be part of the specification of D?

extern(C){
  class Foo{
    int func1();
    int func1(int i);
  }
}

Right now this appears to put Dmangled function names with C calling conventions with a pointer to the object to operate on as the first parameter.

To work with my object from C:
extern int _D6FooMod3Foo5func1UZk(void*);
extern int _D6FooMod3Foo5func1UkZk(void*,int);
{
  void* foo;
  int i;

  foo = get_allocated_object_pointer();
  i = _D6FooMod3Foo5func1UZk(foo);
}

With a few #defines to clean up the mangled function names I have a sane interface into D objects. Can I depend on this behavior?


Thanks,

Traveler Hauptman