www.digitalmars.com         C & C++   DMDScript  

D - Questions

reply Colin JN Breame <Colin_member pathlink.com> writes:
I've just read the article on OSNews and looked at some of the language
reference.

Just a few questions:

- are there any facilities for type introspection?  and attaching meta-data
elements (e.g. to class, function, etc.)?
- can I cast from an array of objects to an array of my type?
- is there support for dynamically loading modules?
- is there any will to standardise the language?
Apr 19 2004
parent reply "C. Sauls" <ibisbasenji yahoo.com> writes:
Comments imbedded: (<-- that's like a catch-phrase around here, I swear)

Colin JN Breame wrote:
 I've just read the article on OSNews and looked at some of the language
 reference.
Glad that, unlike a few of those who commented there, you were willing to give it a shot.
 Just a few questions:
 
 - are there any facilities for type introspection?  and attaching meta-data
 elements (e.g. to class, function, etc.)?
That's being worked on, so I'll leave it for Walter and the others in on that project... but presently we do have some interesting properties for primitive types, and there's the currently un-documented .typeinfo and .classinfo properties for expanding on.
 - can I cast from an array of objects to an array of my type?
If what you mean by this is storing an array of un-specified type, such as Java's Object[] then yes, but you'd use void[].
 - is there support for dynamically loading modules?
Another thing I remember Walter mentioning an interest in (may big-W swat me if I'm mistaken) but I don't know how far along it is.
 - is there any will to standardise the language?
Surely. -C. Sauls -Invironz
Apr 19 2004
parent reply Colin JN Breame <Colin_member pathlink.com> writes:
In article <c60n2p$4ud$1 digitaldaemon.com>, C. Sauls says...
Comments imbedded: (<-- that's like a catch-phrase around here, I swear)

Colin JN Breame wrote:
 I've just read the article on OSNews and looked at some of the language
 reference.
Glad that, unlike a few of those who commented there, you were willing to give it a shot.
Miserable bunch. [snip]
 - can I cast from an array of objects to an array of my type?
If what you mean by this is storing an array of un-specified type, such as Java's Object[] then yes, but you'd use void[].
Is there an equivalent Object class that all classes extend? Also, say I have a void[] that actually contains references to MyType. Can I then cast void[] to MyType[] ??
 - is there support for dynamically loading modules?
Another thing I remember Walter mentioning an interest in (may big-W swat me if I'm mistaken) but I don't know how far along it is.
Am I right in saying that D object files are like C object files? Can a C program call a D function? How about calling D class methods?
 - is there any will to standardise the language?
Surely. -C. Sauls -Invironz
Apr 19 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Colin JN Breame wrote:

  

- is there support for dynamically loading modules?
      
Another thing I remember Walter mentioning an interest in (may big-W swat me if I'm mistaken) but I don't know how far along it is.
Am I right in saying that D object files are like C object files? Can a C program call a D function? How about calling D class methods?
Sure but the dmd lib binaries will only work with dmc. That is you have to use the libs with the same company's c compiler. -- -Anderson: http://badmama.com.au/~anderson/
Apr 19 2004
prev sibling next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
 Miserable bunch.
I just like to think of us as the opressed programmer minority. ;)
 Is there an equivalent Object class that all classes extend?
Yes. -C. Sauls -Invironz
Apr 19 2004
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Replies inline.

Colin JN Breame wrote:
- can I cast from an array of objects to an array of my type?
If what you mean by this is storing an array of un-specified type, such as Java's Object[] then yes, but you'd use void[].
Is there an equivalent Object class that all classes extend? Also, say I have a void[] that actually contains references to MyType. Can I then cast void[] to MyType[] ??
Yes on both counts. There is Object. Like Java, all classes that don't have an explicit base derive from Object. You can cast from a class reference type to Object, and likewise with arrays: Object foo = new MyClass; MyClass[] bar; Object[] baz = bar; Likewise, you can upcast from a base type to a child type. The compiler checks to make sure that the cast is valid, and returns null if not: Object foo = new MyClass; MyClass fred = cast(MyClass)foo; foo = new OtherClass; fred = cast(MyClass)foo; // fred now equals the new object if 'MyClass' is an ancestor // of 'OtherClass'. But if not, it equals null.
 Am I right in saying that D object files are like C object files?  Can a C
 program call a D function?  How about calling D class methods?
D can call C functions, and vice-versa. To declare a C function which can be called by D, you do this: extern(C) int foo(char*); To declare a D function which can be called by C, you do similarly: extern(C) int bar(char*) { <d code here> } As far as linking with C, you have to remember that not all C compilers produce the same type of object files. The idea, however, is for D to produce an object file that can link with C. I know that the Linux D compiler links with GCC object files just fine. You can't call D class methods from C directly. You have two options: 1) Write a trivial wrapper function which is extern(C). 2) Do some casting - but this one might not be portable to a different platform.
Apr 19 2004