D - Questions
- Colin JN Breame (8/8) Apr 19 2004 I've just read the article on OSNews and looked at some of the language
- C. Sauls (15/24) Apr 19 2004 Glad that, unlike a few of those who commented there, you were willing
- Colin JN Breame (8/24) Apr 19 2004 Miserable bunch.
- J Anderson (5/16) Apr 19 2004 Sure but the dmd lib binaries will only work with dmc. That is you have...
- C. Sauls (4/6) Apr 19 2004 Yes.
- Russ Lewis (31/42) Apr 19 2004 Yes on both counts. There is Object. Like Java, all classes that don't...
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
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
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:Miserable bunch. [snip]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.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[] ??- 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[].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 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
Colin JN Breame wrote: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/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 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.
Apr 19 2004
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
Replies inline. Colin JN Breame wrote: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.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[] ??- 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[].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