digitalmars.D - Regarding: import "foo.h";
- Walter Bright (21/21) Jul 17 2013 Over the years, I've given a fair amount of thought to, and talked about...
- Andrej Mitrovic (13/15) Jul 17 2013 But then DMD would have to act as the middle-man between the 3rd
- Walter Bright (2/3) Jul 17 2013 Because the topic comes up now and then.
- Andrej Mitrovic (3/6) Jul 17 2013 I couldn't imagine anyone doing a significant amount of work only
- Walter Bright (13/20) Jul 17 2013 Symantec would not automatically own any derived work, they would only o...
- Brad Roberts (6/22) Jul 17 2013 6. the time cost of parsing/semanticing c/c++ is significantly higher th...
- Jacob Carlborg (5/11) Jul 17 2013 Yeah, that's true. This year Clang has got support for modules.
- Paulo Pinto (8/22) Jul 18 2013 They are not there yet.
- Jacob Carlborg (7/12) Jul 18 2013 If it works for Objective-C, I'm pretty sure it will work for C. In
- Paulo Pinto (8/23) Jul 18 2013 Because that is what Apple is supporting in XCode 5. If you have
- Jesse Phillips (7/7) Jul 17 2013 I think it would be really cool if D could compile in header
- Joseph Rushton Wakeling (7/12) Jul 17 2013 I take it using a different C/C++ frontend (such as clang) is out, at le...
- Jacob Carlborg (5/6) Jul 17 2013 Yes, it's always the preprocessor that's causing the problems, including...
- Jacob Carlborg (5/10) Jul 17 2013 Yes, that's why a library like libclang should be used.
- Dicebot (7/11) Jul 18 2013 Those two plus the fact that h->d conversion is fairly static and
- Kapps (12/15) Jul 18 2013 Personally I'd rather see something like this as part of a more
Over the years, I've given a fair amount of thought to, and talked about it with various people: import "foo.h"; or something similar as a way to interface existing C (or even C++) code to D. On the plus side, I have a C/C++ front end which could be adapted to do this. On the minus, 1. there may be various #define's necessary to compile it that would normally be supplied on the command line to the C compiler 2. there are various behavior switches (see the PR for DMD that wants to set the signed'ness of char types) 3. rather few .h files seem to be standard compliant C. They always rely on various compiler extensions 4. the license would be the same as for the back end 5. having a C/C++ front end as a "bag on the side" of a D compiler seems like a heavy burden to anyone wanting to write a D compiler, besides being a fairly massive maintenance effort as it would have to be kept up with the latest C/C++ standards and extensions Essentially, I think it is impractical, and in the worst case scenario, could actually sink D because of the diversion of effort necessary. Instead, any such tool should be a separate tool, designed, built, and maintained separately. Perhaps DMD could call it like it calls the linker.
Jul 17 2013
On Wednesday, 17 July 2013 at 22:52:40 UTC, Walter Bright wrote:Perhaps DMD could call it like it calls the linker.But then DMD would have to act as the middle-man between the 3rd party tool and the header files (e.g. it would have to pass custom flags to the tool, there's no question how many flags could exist..). I don't see much benefit to it. It also doesn't help that `import "foo.h"` does who-knows-what behind the scenes, for example there's the question of which generated D module is actually then imported, and what do the actual D declarations look like? The user has to know, otherwise he can't use the wrapper code just by looking at the foo.h header file. On Wednesday, 17 July 2013 at 22:52:40 UTC, Walter Bright wrote:4. the license would be the same as for the back endWhy even bother starting this thread?
Jul 17 2013
On 7/17/2013 4:01 PM, Andrej Mitrovic wrote:Why even bother starting this thread?Because the topic comes up now and then.
Jul 17 2013
On Wednesday, 17 July 2013 at 23:10:36 UTC, Walter Bright wrote:On 7/17/2013 4:01 PM, Andrej Mitrovic wrote:I couldn't imagine anyone doing a significant amount of work only to have their work marked with a DigitalMars & Symantec stamp.Why even bother starting this thread?Because the topic comes up now and then.
Jul 17 2013
On 7/17/2013 4:18 PM, Andrej Mitrovic wrote:On Wednesday, 17 July 2013 at 23:10:36 UTC, Walter Bright wrote:Symantec would not automatically own any derived work, they would only own the original. As for DM, yes, it'd be necessary to assign copyright to DM. Otherwise, having source files with a dozen different copyrights on various lines of code in it is completely impractical. Tango got into difficulty, for example, because various people owned various copyrights in it, meaning that the license could not be changed as it was hard to reach them all, let alone get any sort of consensus agreement. These kinds of issues are, of course, why Phobos is Boost licensed. And lastly, the use of github ensures that contributors get credit for their work regardless of license/copyright issues. It's just one of the things that makes github such a great collaborative tool for us.On 7/17/2013 4:01 PM, Andrej Mitrovic wrote:I couldn't imagine anyone doing a significant amount of work only to have their work marked with a DigitalMars & Symantec stamp.Why even bother starting this thread?Because the topic comes up now and then.
Jul 17 2013
On 7/17/13 3:52 PM, Walter Bright wrote:Over the years, I've given a fair amount of thought to, and talked about it with various people: import "foo.h"; or something similar as a way to interface existing C (or even C++) code to D. On the plus side, I have a C/C++ front end which could be adapted to do this. On the minus, 1. there may be various #define's necessary to compile it that would normally be supplied on the command line to the C compiler 2. there are various behavior switches (see the PR for DMD that wants to set the signed'ness of char types) 3. rather few .h files seem to be standard compliant C. They always rely on various compiler extensions 4. the license would be the same as for the back end 5. having a C/C++ front end as a "bag on the side" of a D compiler seems like a heavy burden to anyone wanting to write a D compiler, besides being a fairly massive maintenance effort as it would have to be kept up with the latest C/C++ standards and extensions Essentially, I think it is impractical, and in the worst case scenario, could actually sink D because of the diversion of effort necessary. Instead, any such tool should be a separate tool, designed, built, and maintained separately. Perhaps DMD could call it like it calls the linker.6. the time cost of parsing/semanticing c/c++ is significantly higher than D, making .h importing dwarf the rest of the cost of the compilation process 7. .h files are roughly static so translating them on each compilation unit is wasteful, generate once as part of the build process and update only as needed. This is stuff that build processes are good at.
Jul 17 2013
On 2013-07-18 01:53, Brad Roberts wrote:6. the time cost of parsing/semanticing c/c++ is significantly higher than D, making .h importing dwarf the rest of the cost of the compilation process 7. .h files are roughly static so translating them on each compilation unit is wasteful, generate once as part of the build process and update only as needed. This is stuff that build processes are good at.Yeah, that's true. This year Clang has got support for modules. Basically a better and safe(er) version of percompiled headers. -- /Jacob Carlborg
Jul 17 2013
On Thursday, 18 July 2013 at 06:35:21 UTC, Jacob Carlborg wrote:On 2013-07-18 01:53, Brad Roberts wrote:They are not there yet. I was really looking forward for it, mostly due to the C++17 modules effort being done at Apple. However, what was presented at WWDC 2013 was a half baked solution that only works in Objective-C for system headers. -- Paulo6. the time cost of parsing/semanticing c/c++ is significantly higher than D, making .h importing dwarf the rest of the cost of the compilation process 7. .h files are roughly static so translating them on each compilation unit is wasteful, generate once as part of the build process and update only as needed. This is stuff that build processes are good at.Yeah, that's true. This year Clang has got support for modules. Basically a better and safe(er) version of percompiled headers.
Jul 18 2013
On 2013-07-18 09:36, Paulo Pinto wrote:They are not there yet. I was really looking forward for it, mostly due to the C++17 modules effort being done at Apple. However, what was presented at WWDC 2013 was a half baked solution that only works in Objective-C for system headers.If it works for Objective-C, I'm pretty sure it will work for C. In fact, the documentation contains a lot of examples with standard C headers. http://clang.llvm.org/docs/Modules.html Why would they work only for system headers? -- /Jacob Carlborg
Jul 18 2013
On Thursday, 18 July 2013 at 08:23:42 UTC, Jacob Carlborg wrote:On 2013-07-18 09:36, Paulo Pinto wrote:Because that is what Apple is supporting in XCode 5. If you have an Apple ID, have a look at, Session "Advances in Objective-C" https://developer.apple.com/wwdc/videos Slides from page 9 up to 69. Slide 61 lists all current caveats. -- PauloThey are not there yet. I was really looking forward for it, mostly due to the C++17 modules effort being done at Apple. However, what was presented at WWDC 2013 was a half baked solution that only works in Objective-C for system headers.If it works for Objective-C, I'm pretty sure it will work for C. In fact, the documentation contains a lot of examples with standard C headers. http://clang.llvm.org/docs/Modules.html Why would they work only for system headers?
Jul 18 2013
I think it would be really cool if D could compile in header files. But also agree the tradeoffs really suck. And if DMD does it as a compiler extension then it is as good as required. If it was done in LDC or GDC I wouldn't consider it a problem at all. Ultimately an easy to install 3rd party program should be fine. I haven't needed to convert header files for a while so never attempted dstep yet.
Jul 17 2013
On 07/18/2013 12:52 AM, Walter Bright wrote:4. the license would be the same as for the back endI take it using a different C/C++ frontend (such as clang) is out, at least for DMD ... ?Essentially, I think it is impractical, and in the worst case scenario, could actually sink D because of the diversion of effort necessary. Instead, any such tool should be a separate tool, designed, built, and maintained separately. Perhaps DMD could call it like it calls the linker.Personally I don't mind whether it's part of the compiler or a separate tool, as long as there is a solution available that makes it easy to link to C/C++ code without having to manually write bindings. Though I imagine that for optimal performance, some manual work will always be necessary.
Jul 17 2013
On 2013-07-18 07:54, Joseph Rushton Wakeling wrote:Though I imagine that for optimal performance, some manual work will always be necessary.Yes, it's always the preprocessor that's causing the problems, including #includes. -- /Jacob Carlborg
Jul 17 2013
On 2013-07-18 00:52, Walter Bright wrote:4. the license would be the same as for the back endThe license of what?5. having a C/C++ front end as a "bag on the side" of a D compiler seems like a heavy burden to anyone wanting to write a D compiler, besides being a fairly massive maintenance effort as it would have to be kept up with the latest C/C++ standards and extensionsYes, that's why a library like libclang should be used. -- /Jacob Carlborg
Jul 17 2013
On Wednesday, 17 July 2013 at 22:52:40 UTC, Walter Bright wrote:1. there may be various #define's necessary to compile it that would normally be supplied on the command line to the C compiler 2. there are various behavior switches (see the PR for DMD that wants to set the signed'ness of char types)Those two plus the fact that h->d conversion is fairly static and should not be done at compilation stage is pretty much enough for me to oppose such misfeature. Everything else is not that relevant. Even if the idea was considered good, pulling in more dmc legacy is the last thing I'd be glad to see done.
Jul 18 2013
On Wednesday, 17 July 2013 at 22:52:40 UTC, Walter Bright wrote:Over the years, I've given a fair amount of thought to, and talked about it with various people: import "foo.h";Personally I'd rather see something like this as part of a more generic feature rather than built in to the compiler. If CTFE could call external libraries or programs, such as utilizing libclang for parsing (and ideally if it could perform caching of [pure?] mixins that took more than X to evaluate), it would be nicer than including a C parser inside a D compiler. Then it's the responsibility of the project / package manager to make sure that the dependency is present and also avoids certain licensing / maintainability issues. Not sure how feasible having CTFE be able to call external libraries is though, or if it would be desired.
Jul 18 2013