www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - using C with D

reply Micah Heyer <Hacim.H gmail.com> writes:
Hi everyone,
  Lately I've been taking another look at D and I've been thinking about 
using it instead of c++,but the single most thing holding me back is the 
ability to use C libraries with out having to recreate the headers.I 
understand why this feature was left out of D,but with out the ability 
to easily use C libraries I just have to stick with C++.To me one of the 
  strengths of C++ and probably one of the reasons it is in use as much 
as it is to day is that it is backwards compatible with C.
So here is what I'm wondering: would it be possible, through 
modification of gcc,to have the compiler export a D style symbol table 
for importing into D projects?Is this a ridiculous idea or would it 
actully be feasible?

-micah
Jul 21 2007
parent reply Gregor Richards <Richards codu.org> writes:
Micah Heyer wrote:
 Hi everyone,
  Lately I've been taking another look at D and I've been thinking about 
 using it instead of c++,but the single most thing holding me back is the 
 ability to use C libraries with out having to recreate the headers.I 
 understand why this feature was left out of D,but with out the ability 
 to easily use C libraries I just have to stick with C++.To me one of the 
  strengths of C++ and probably one of the reasons it is in use as much 
 as it is to day is that it is backwards compatible with C.
 So here is what I'm wondering: would it be possible, through 
 modification of gcc,to have the compiler export a D style symbol table 
 for importing into D projects?Is this a ridiculous idea or would it 
 actully be feasible?
 
 -micah
Not only is it feasible, I did it months ago. http://www.dsource.org/projects/bcd/ - Gregor Richards
Jul 21 2007
next sibling parent reply "Saaa" <empty needmail.com> writes:
What exactly is the difference between bcd and htod?
I've read both of the websites and am I right to say they both rewrite the 
header file to a D compatible module?

 Not only is it feasible, I did it months ago.

 http://www.dsource.org/projects/bcd/

  - Gregor Richards 
Jul 21 2007
next sibling parent reply Gregor Richards <Richards codu.org> writes:
Saaa wrote:
 What exactly is the difference between bcd and htod?
 I've read both of the websites and am I right to say they both rewrite the 
 header file to a D compatible module?
 
 Not only is it feasible, I did it months ago.

 http://www.dsource.org/projects/bcd/

  - Gregor Richards 
1) bcd.gen is F/OSS 2) bcd.gen is portable 3) bcd.gen supports (limited) C++ - Gregor Richards
Jul 22 2007
parent reply "Saaa" <empty needmail.com> writes:
Ah ok :)

Just a question, nothing concrete, but should I report faulty translations? 
(.h(C) to .d)
Or do you know of limitations(such as Sean Kelly reports about htod)

 1) bcd.gen is F/OSS
 2) bcd.gen is portable
 3) bcd.gen supports (limited) C++

  - Gregor Richards 
Jul 22 2007
parent reply Gregor Richards <Richards codu.org> writes:
Saaa wrote:
 Ah ok :)
 
 Just a question, nothing concrete, but should I report faulty translations? 
 (.h(C) to .d)
 Or do you know of limitations(such as Sean Kelly reports about htod)
 
 1) bcd.gen is F/OSS
 2) bcd.gen is portable
 3) bcd.gen supports (limited) C++

  - Gregor Richards 
Macros are always a problem, but I haven't found them as problematic with bcd.gen as Sean apparently has with htod. I don't know if this is due to different implementation, or just because I haven't tested bcd.gen on the same kinds of things. Yes, report failures directly to my email. I may or may not fix :P Confusing very things makes it, newsgroups in post-top don't please, way the by. - Gregor Richards
Jul 22 2007
next sibling parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Gregor Richards wrote:
 Saaa wrote:
 Ah ok :)

 Just a question, nothing concrete, but should I report faulty 
 translations? (.h(C) to .d)
 Or do you know of limitations(such as Sean Kelly reports about htod)

 1) bcd.gen is F/OSS
 2) bcd.gen is portable
 3) bcd.gen supports (limited) C++

  - Gregor Richards 
Macros are always a problem, but I haven't found them as problematic with bcd.gen as Sean apparently has with htod. I don't know if this is due to different implementation, or just because I haven't tested bcd.gen on the same kinds of things. Yes, report failures directly to my email. I may or may not fix :P Confusing very things makes it, newsgroups in post-top don't please, way the by. - Gregor Richards
The sad and scary thing is... I had to read that last line a few times before it occured to me what was strange about it... 0_o Must be my 0.125 Dutch blood coming through. Ik begrijp u. Ik ben niet trots van het. ;p -- Chris Nicholson-Sauls
Jul 24 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Chris Nicholson-Sauls,

 Gregor Richards wrote:

 Confusing very things makes it, newsgroups in post-top don't please,
 way the by.
 
 - Gregor Richards
 
The sad and scary thing is... I had to read that last line a few times before it occured to me what was strange about it... 0_o Must be my 0.125 Dutch blood coming through. Ik begrijp u. Ik ben niet trots van het. ;p
http://www.metafilter.com/28301/Scrambled-Text
Jul 24 2007
next sibling parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
BCS wrote:
 Reply to Chris Nicholson-Sauls,
 
 Gregor Richards wrote:

 Confusing very things makes it, newsgroups in post-top don't please,
 way the by.

 - Gregor Richards
The sad and scary thing is... I had to read that last line a few times before it occured to me what was strange about it... 0_o Must be my 0.125 Dutch blood coming through. Ik begrijp u. Ik ben niet trots van het. ;p
For the non-Dutch-speaking audience: "Ik begrijp u" == "I understand you" (though "u" is the formal form of "you", and I'd probably have used the informal "je" in that sentence). That second sentence should probably be "Ik ben er niet trots op". The way you wrote it looks like a Babelfish-like translation of "I'm not proud of it" (i.e. a dictionary-in-hand/browser word-for-word translation, seemingly not taking grammar into account). I'm not sure why you'd bring up Dutch though, except perhaps as a reason to be used to words being in the "wrong" order. (I'm pretty sure the word order Gregor used makes about as little sense in Dutch as in English, and Gregor seems be from Portland...)
Jul 24 2007
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Frits van Bommel wrote:
 BCS wrote:
 Reply to Chris Nicholson-Sauls,

 Gregor Richards wrote:

 Confusing very things makes it, newsgroups in post-top don't please,
 way the by.

 - Gregor Richards
The sad and scary thing is... I had to read that last line a few times before it occured to me what was strange about it... 0_o Must be my 0.125 Dutch blood coming through. Ik begrijp u. Ik ben niet trots van het. ;p
For the non-Dutch-speaking audience: "Ik begrijp u" == "I understand you" (though "u" is the formal form of "you", and I'd probably have used the informal "je" in that sentence). That second sentence should probably be "Ik ben er niet trots op". The way you wrote it looks like a Babelfish-like translation of "I'm not proud of it" (i.e. a dictionary-in-hand/browser word-for-word translation, seemingly not taking grammar into account). I'm not sure why you'd bring up Dutch though, except perhaps as a reason to be used to words being in the "wrong" order. (I'm pretty sure the word order Gregor used makes about as little sense in Dutch as in English, and Gregor seems be from Portland...)
Dictionary in hand, it was, I'll admit it. :) I haven't actually used any Dutch in almost seven years... it was an excuse to go digging through crates for that dictionary. Never know what other nifty things you'll find buried away in your own closets. As to the reason... yeah, that's basically it, although yes the case in point makes no sense either way. But one thing I've noticed is the Dutch end of my family has a peculiar tendency to utter ubiquitous phrases somewhat scrambled. Don't really know why, but it happens. -- Chris Nicholson-Sauls
Jul 24 2007
prev sibling parent BCS <ao pathlink.com> writes:
Reply to Benjamin,

 Reply to Chris Nicholson-Sauls,
 
 Gregor Richards wrote:
 
 Confusing very things makes it, newsgroups in post-top don't please,
 way the by.
 
 - Gregor Richards
 
The sad and scary thing is... I had to read that last line a few times before it occured to me what was strange about it... 0_o Must be my 0.125 Dutch blood coming through. Ik begrijp u. Ik ben niet trots van het. ;p
http://www.metafilter.com/28301/Scrambled-Text
The mind can read through a lot of mangling
Jul 24 2007
prev sibling parent reply Gregor Richards <Richards codu.org> writes:
Gregor Richards wrote:
 Saaa wrote:
 Ah ok :)

 Just a question, nothing concrete, but should I report faulty 
 translations? (.h(C) to .d)
 Or do you know of limitations(such as Sean Kelly reports about htod)

 1) bcd.gen is F/OSS
 2) bcd.gen is portable
 3) bcd.gen supports (limited) C++

  - Gregor Richards 
Macros are always a problem, but I haven't found them as problematic with bcd.gen as Sean apparently has with htod. I don't know if this is due to different implementation, or just because I haven't tested bcd.gen on the same kinds of things. Yes, report failures directly to my email. I may or may not fix :P Confusing very things makes it, newsgroups in post-top don't please, way the by. - Gregor Richards
Oh come on people :P It's not scrambled, it's backwards, it says: By the way, please don't top-post in newsgroups, it makes things very confusing. Get it? Get it? Yeesh. - Gregor Richards
Jul 24 2007
parent Derek Parnell <derek psyc.ward> writes:
What do you mean?

--
Derek Parnell
Melbourne, Australia
"giggles"

On Tue, 24 Jul 2007 19:54:56 -0700, Gregor Richards wrote:

 Gregor Richards wrote:
 Saaa wrote:
 Ah ok :)

 Just a question, nothing concrete, but should I report faulty 
 translations? (.h(C) to .d)
 Or do you know of limitations(such as Sean Kelly reports about htod)

 1) bcd.gen is F/OSS
 2) bcd.gen is portable
 3) bcd.gen supports (limited) C++

  - Gregor Richards 
Macros are always a problem, but I haven't found them as problematic with bcd.gen as Sean apparently has with htod. I don't know if this is due to different implementation, or just because I haven't tested bcd.gen on the same kinds of things. Yes, report failures directly to my email. I may or may not fix :P Confusing very things makes it, newsgroups in post-top don't please, way the by. - Gregor Richards
Oh come on people :P It's not scrambled, it's backwards, it says: By the way, please don't top-post in newsgroups, it makes things very confusing. Get it? Get it? Yeesh. - Gregor Richards
Jul 24 2007
prev sibling parent Sean Kelly <sean f4.ca> writes:
Saaa wrote:
 What exactly is the difference between bcd and htod?
 I've read both of the websites and am I right to say they both rewrite the 
 header file to a D compatible module?
I haven't tried bcd yet, but in my experience, htod doesn't actually work that well for headers including macros (which seems to be most C headers I've actually needed to convert). I found it was often faster to convert headers by hand than it was to run them through htod and then do manual cleanup afterwards. Sean
Jul 22 2007
prev sibling next sibling parent "Anders Bergh" <anders1 gmail.com> writes:
On 7/22/07, Gregor Richards <Richards codu.org> wrote:
 Not only is it feasible, I did it months ago.

 http://www.dsource.org/projects/bcd/
I don't think I've thanked you for bcd... it's a great tool! It works on nearly anything I feed it. -- Anders
Jul 21 2007
prev sibling parent reply Micah Heyer <Hacim.H gmail.com> writes:
Gregor Richards wrote:
 
 Not only is it feasible, I did it months ago.
 
 http://www.dsource.org/projects/bcd/
 
  - Gregor Richards
Ah, thats a nifty little program,I think info about it should be placed in the faq.One question though: What's all the aliased function pointers I keep getting in the output? alias int function(void *, void *) _BCD_func__788; alias int function(void *) _BCD_func__409; alias int function(void *, long *, int) _BCD_func__411; alias int function(void *, char *, uint) _BCD_func__413; alias int function(void *, char *, uint) _BCD_func__415; alias void function(void *) _BCD_func__895; alias int function(void * *, char *) _BCD_func__896; alias int function(char *, char * * *, uint *) _BCD_func__897; alias int function(void *, char *, char *, char *, char *) _BCD_func__898; alias int function(__gconv_step *, __gconv_step_data *, void *, char *, char * *, char *, char * *, uint *) _BCD_func__899; alias void function(__gconv_step *) _BCD_func__900; alias int function(__gconv_step *) _BCD_func__901; alias uint function(__gconv_step *, char) _BCD_func__902; alias int function(__gconv_step *, __gconv_step_data *, char * *, char *, char * *, uint *, int, int) _BCD_func__903; I was converting sdl headers btw. -micah
Jul 23 2007
parent Gregor Richards <Richards codu.org> writes:
Micah Heyer wrote:
 Gregor Richards wrote:
 Not only is it feasible, I did it months ago.

 http://www.dsource.org/projects/bcd/

  - Gregor Richards
Ah, thats a nifty little program,I think info about it should be placed in the faq.One question though: What's all the aliased function pointers I keep getting in the output? alias int function(void *, void *) _BCD_func__788; alias int function(void *) _BCD_func__409; alias int function(void *, long *, int) _BCD_func__411; alias int function(void *, char *, uint) _BCD_func__413; alias int function(void *, char *, uint) _BCD_func__415; alias void function(void *) _BCD_func__895; alias int function(void * *, char *) _BCD_func__896; alias int function(char *, char * * *, uint *) _BCD_func__897; alias int function(void *, char *, char *, char *, char *) _BCD_func__898; alias int function(__gconv_step *, __gconv_step_data *, void *, char *, char * *, char *, char * *, uint *) _BCD_func__899; alias void function(__gconv_step *) _BCD_func__900; alias int function(__gconv_step *) _BCD_func__901; alias uint function(__gconv_step *, char) _BCD_func__902; alias int function(__gconv_step *, __gconv_step_data *, char * *, char *, char * *, uint *, int, int) _BCD_func__903; I was converting sdl headers btw. -micah
Because of how GCCXML works internally, it's easier to alias the functions to alternative names in one step, and then use those alternative names in another step. It's a bit weird, but it doesn't make life any more difficult so long as you stick to this one rule: Don't use the generated .d files as documentation, use the .h files :) - Gregor Richards PS: The lines with gconv_step is a bug I haven't tracked down. It's easy to fix the generated headers by just removing those lines.
Jul 23 2007