www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - can D compiler support C/C++ source code?

reply donglei <langhao2010 163.com> writes:
While D is binary compatible with C code, it cannot compile C 
code nor C header files.
In order to use C/C++ binary libs, I have to convert C or C++ 
header files to D module.
It make very difficult to use C binary libs.
Can D compiler support C/C++ source code in future?
If can, it will become easy and convenient to use C/C++ libs in 
Dlang.
Hope to achieve it as soon as possible!
Sep 20 2015
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 21/09/15 5:24 PM, donglei wrote:
 While D is binary compatible with C code, it cannot compile C code nor C
 header files.
 In order to use C/C++ binary libs, I have to convert C or C++ header
 files to D module.
 It make very difficult to use C binary libs.
 Can D compiler support C/C++ source code in future?
 If can, it will become easy and convenient to use C/C++ libs in Dlang.
 Hope to achieve it as soon as possible!
What you are asking for is a c/c++ frontend as part of the D compiler, which is completely infeasible. There are attempts such as Calypso to use an existing c++ front end to generate D bindings. But even they have a hard time, especially with STL. This is not going to happen. You will need to create bindings some way or another. They are easy and simple to do.
Sep 20 2015
next sibling parent Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Monday, 21 September 2015 at 05:32:52 UTC, Rikki Cattermole 
wrote:
 What you are asking for is a c/c++ frontend as part of the D 
 compiler, which is completely infeasible.
Making a c frontend part of the compiler should be feasible. I can think of several distinct approaches.
Sep 21 2015
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Monday, 21 September 2015 at 05:32:52 UTC, Rikki Cattermole 
wrote:
 What you are asking for is a c/c++ frontend as part of the D 
 compiler, which is completely infeasible.
Of course it's feasible, but it would mean that the D compiler would have to have a full-blown C++ compiler built into it, and we don't want that maintenance nightmare, and we certainly don't want to put in the time and effort that would be required to do it. D already has far better support for C/C++ than is typical of languages which aren't C or C++, and it may improve further, but there are limits to what is reasonable to do, and it's been stated on multiple occasions that we don't want to implement C/C++ in the D compiler. - Jonathan M Davis
Sep 21 2015
prev sibling next sibling parent Sean Campbell <sycam.inc gmail.com> writes:
On Monday, 21 September 2015 at 05:25:01 UTC, donglei wrote:
 While D is binary compatible with C code, it cannot compile C 
 code nor C header files.
 In order to use C/C++ binary libs, I have to convert C or C++ 
 header files to D module.
 It make very difficult to use C binary libs.
 Can D compiler support C/C++ source code in future?
 If can, it will become easy and convenient to use C/C++ libs in 
 Dlang.
 Hope to achieve it as soon as possible!
unfortunately no... as stated at http://dlang.org/cpp_interface.html to support C/C++ source would be practically unimplementable note I say practically because while theoretically it is possible, the D community has neither the resources nor the time to implement such a feature. If you look around D.announce I seem to remember someone hacked up LLVM and clang to allow such interface.
Sep 20 2015
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2015-09-21 07:24, donglei wrote:
 While D is binary compatible with C code, it cannot compile C code nor C
 header files.
 In order to use C/C++ binary libs, I have to convert C or C++ header
 files to D module.
 It make very difficult to use C binary libs.
 Can D compiler support C/C++ source code in future?
 If can, it will become easy and convenient to use C/C++ libs in Dlang.
 Hope to achieve it as soon as possible!
For C, there's a tool called DStep [1] that can automatically generate bindings. It's not 100% perfect but will get you a long way. [1] https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg
Sep 20 2015
prev sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
On Monday, 21 September 2015 at 05:25:01 UTC, donglei wrote:
 While D is binary compatible with C code, it cannot compile C 
 code nor C header files.
 In order to use C/C++ binary libs, I have to convert C or C++ 
 header files to D module.
 It make very difficult to use C binary libs.
 Can D compiler support C/C++ source code in future?
 If can, it will become easy and convenient to use C/C++ libs in 
 Dlang.
 Hope to achieve it as soon as possible!
There is https://github.com/Syniurge/Calypso
Sep 20 2015