Vala could replace C ...

Walter Bright newshound1 at digitalmars.com
Mon Sep 3 21:13:13 PDT 2007


Charles D Hixson wrote:
> Even building a D library isn't "easy".  Were I to attempt it, I'd use 
> GDC (which currently means limiting myself to a subset of D's features).

Building a library is as easy as building the obj's, then putting them 
into a library with lib or ar. Granted, dmd could build the library 
itself like it does the link itself.

> It's also not clear (to me) how to call a D routine from a program whose 
> main routine is written in another language. This is a significant 
> limitation...especially when more than one language makes it difficult.

If you give the D routine C linkage, with extern (C), you can call it 
directly from any language that supports C (including, of course, C!).

> FWIW, D's compatibility with C is better than that of most languages.  
> This doesn't make it good.  I understand the problem caused by macros in 
> header files...but they are a severe impediment to "very easy 
> compatibility".  "Very easy compatibility" (my definition) means that I 
> take of chunk of C code in multiple separate files linked by header 
> files, and replace on of the files with a chunk of D code that performs 
> an equivalent function.  This isn't possible, and probably isn't going 
> to be possible.  At any rate, not until interpretation of C header files 
> is handled.

The h2d.exe program will convert C headers to D import files. It isn't 
perfect, but it does a pretty good job of it.

> I'm more or less in awe of the manipulations that can be done with 
> templates...but I'm never going to be interested in using them at more 
> than a very basic level.

That's ok. The advanced stuff is there for the folks who need it, for 
bread & butter programmers it can be ignored. But, I also intend to make 
it so easy to do templates, you won't even notice you're using them!

> I am more interested in run-time flexibility 
> rather than in compile time flexibility.  Importing C header files, 
> though, would immediately move D up to "The Single Most Superior 
> Language" in my books.  (OK. I read the comments a few years ago, and 
> you were advised that this was a can of worms and should be avoided.  
> It's probably right.  But it would be *SO* convenient.)
> 
> Another thing that would be useful is a specific and well documented 
> entry point in the libraries (probably std.compiler or std.object) that 
> could be called to do all necessary initializations if the main routine 
> were, e.g., C.

That's a good suggestion.


> OTOH, you notice that I'm posting here.  D appears a better language for 
> me to use than any other.  Just not perfect.  So for the moment I'm 
> doing etudes in C that I'll eventually link to D routines.  This will 
> let me call C object files and libraries from D with only a lot of extra 
> work and indirection.  Ugly and inconvenient, but better than the 
> obvious alternatives.



More information about the Digitalmars-d-announce mailing list