A gentle critque..

Anders F Björklund afb at algonet.se
Mon May 15 01:14:40 PDT 2006


Chad J wrote:

>> Translating C++ headers is trickier, but can be done too if needed...
> 
> Is there a good tool for C plus plus to C to D translation?

Not really, and it's a two-step process.

First you need to export all the C++ methods as "C" functions.
Then you need to write at least an import module, and probably
a class wrapper too, for all those exported procedural functions ?

> I think I confused the term "linking" with... I don't even know what to 
> call it then.  C plus plus integration maybe.

Sorry, the "dropping of the plusses" added some confusion there.

D does have linkage with C functions (minus vectors, and some other
advanced things that C extensions offers), but *not* for C++.

So the only way to link with C++ is to first: export "C" { }

> I'd like to see that perl hack.  Is it online somewhere?

http://www.algonet.se/~afb/d/h2d.pl

There is no parsing and no understanding, it just searches/replaces.
It does try to use the C #defines, but sometimes it gets really 
confused. The way I use it is that I run it on the C headers, and
then I run a "diff" to fix the parts where it screwed up.

Some parts, like tricky macros, need to be rewritten from scratch.
So it's not really an automated solution, just a little "crutch"
(see the SDL and GL/AL headers from that same URL, for more examples)

> I remember trying SWIG to get some C plus plus to D conversion going on, 
> but that setup didn't work very well.  Required a lot of work just to 
> use it.  Cure is worst than the disease sort of thing.

SWIG is nice (when it works), but it's a huge project in itself...

> I noticed an h2d project on dsource.  But I think that only worked on 
> linux, or something.  For some reason I wasn't able to even try it.

It has some really nasty C++ dependencies. Tried to use it, but...

> I don't remember seeing any tools of this kind that were written in D. 
> Kind of unfortunate, probably makes it difficult to pool effort out of D 
> programmers for something that isn't written in D.

I think that such a tool would be a good "exercise" for D, and
could become highly useful too - just like Build has become ?

But I started out with the missing GUI and IDE instead, myself.

--anders



More information about the Digitalmars-d mailing list