January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nestor | On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
> Hi friends,
>
> Is there a way to "compile" d code to C, similar to what nim does?
>
> That would be cool for greater portability.
Nim is able to, because Nim doesn't really compile. The Nim compiler just translates Nim code to C code and then compiles the C code.
It's much harder to do properly in D, because D doesn't use C as a backend, but compiles directly to native.
I'd guess the code generation you'd get from doing so with D would be absolute horrific to read, because you'll get rid of CTFE, templates, proper class structure, globals properly stored, since everything in D is TLS and C doesn't then you'll see weird constructs everywhere.
If you ask me, it's probably not something you want to do and there really isn't a reason to do it with D either. D has an almost 100% compatibility with C already.
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bauss | On Monday, 23 January 2017 at 14:53:54 UTC, Bauss wrote:
> I'd guess the code generation you'd get from doing so with D would be absolute horrific to read, because you'll get rid of CTFE, templates, proper class structure, globals properly stored, since everything in D is TLS and C doesn't then you'll see weird constructs everywhere.
TLS is a nonissue. You can wrap the TLS declarations in macros.
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | On Monday, 23 January 2017 at 14:40:18 UTC, Ola Fosheim Grøstad wrote:
> On Saturday, 21 January 2017 at 19:30:31 UTC, Jack Stouffer wrote:
>> On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote:
>>> Hi friends,
>>>
>>> Is there a way to "compile" d code to C, similar to what nim does?
>>>
>>> That would be cool for greater portability.
>>
>> No, and this is actually a terrible idea. See https://forum.dlang.org/post/n1vbos$11ov$1@digitalmars.com
>
> No valid arguments for it being a terrible idea in that thread.
>
> Being able to translate code to other languages is a very useful feature and makes a language much more interesting in production.
Unless you will be limited by tge limitations of C. Vala programming language has that issue even though they utilize GObject
|
January 23, 2017 Re: Compile to C? | ||||
---|---|---|---|---|
| ||||
Posted in reply to aberba | On Monday, 23 January 2017 at 15:24:09 UTC, aberba wrote:
> Unless you will be limited by tge limitations of C. Vala programming language has that issue even though they utilize GObject
What limitations? C/C++ programs go around "limitations" by using compiler extensions and runtime libraries.
Vala is trying to keep code simple, like Go. Apples and oranges.
|
Copyright © 1999-2021 by the D Language Foundation