www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Documentation re -betterC compatibility with standard library

reply DLearner <bmqazwsx123 gmail.com> writes:
Is there a definitive list somewhere of standard library 
functions that work with -betterC?

For example, the following code fragment (taken from the library 
docs) does not work with -betterC.
```
extern(C) void main() {
    import std.container.array;

    auto arr = Array!int(0, 2, 3);


}
```
Jan 28
next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, January 28, 2025 6:01:56 AM MST DLearner via Digitalmars-d-learn
wrote:
 Is there a definitive list somewhere of standard library
 functions that work with -betterC?

 For example, the following code fragment (taken from the library
 docs) does not work with -betterC.
 ```
 extern(C) void main() {
     import std.container.array;

     auto arr = Array!int(0, 2, 3);


 }
 ```
No, certainly not an official one, and it arguably wouldn't make sense to make one, because we do not support -betterC with druntimte or Phobos, and for the most part, anywhere it works is accidental. In a few cases, someone went in and explicitly made something work with -betterC, but we provide no guarantees that any code that works with -betterC right now will continue to do so, and we do not intend to add -betterC support. So, if you use something from Phobos that happens to work with -betterC today, it could stop working with -betterC tomorrow if a change is made to fix or improve something, and it's not compatible with -betterC. -betterC was originally intended to be a tool for making it easier to port C code to D code (after which, the idea was that -betterC would no longer be used, and you would just have a normal D program). It was never the goal to use it to create a secondary version of D. Some folks have elected to use it that way, and that's fine, but you're basically on your own if you're using -betterC. The compiler is really the only thing that explicitly supports it, and of course, it doesn't support all D features with it, because it can't. The closest that you're likely to ever get for -betterC support is that we want to try to make it so that stuff in druntime is more pay as you go - that is, if it really doesn't need something, it doesn't pull it in, so you then hopefully you don't pull in code that you're not using - and that would naturally make more stuff work with -betterC, but we're not going to explicitly support -betterC with druntime or Phobos. - Jonathan M Davis
Jan 28
next sibling parent reply Dennis <dkorpel gmail.com> writes:
On Tuesday, 28 January 2025 at 15:00:13 UTC, Jonathan M Davis 
wrote:
 but we provide no guarantees that any code that works with 
 -betterC right now will continue to do so, and we do not intend 
 to add -betterC support. So, if you use something from Phobos 
 that happens to work with -betterC today, it could stop working 
 with -betterC tomorrow if a change is made to fix or improve 
 something, and it's not compatible with -betterC.
There are betterC unittests in Phobos. Those could be modified, but I'd say those unittests give soft guarantees of whatever functions they're testing working with -betterC.
Jan 28
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, January 28, 2025 8:04:36 AM MST Dennis via Digitalmars-d-learn
wrote:
 On Tuesday, 28 January 2025 at 15:00:13 UTC, Jonathan M Davis
 wrote:
 but we provide no guarantees that any code that works with
 -betterC right now will continue to do so, and we do not intend
 to add -betterC support. So, if you use something from Phobos
 that happens to work with -betterC today, it could stop working
 with -betterC tomorrow if a change is made to fix or improve
 something, and it's not compatible with -betterC.
There are betterC unittests in Phobos. Those could be modified, but I'd say those unittests give soft guarantees of whatever functions they're testing working with -betterC.
There are some, but there aren't many, and the're there because an individual developer decided to go in there and add them. When -betterC came up in DLF meeting a few months ago, it was decided that we definitely weren't supporting it with the standard library and that folks were on their own when using it (outside of compiler support, of course). It's also the current plan that Phobos v3 will not be supporting -betterC. So, yes, those few items in Phobos that currently have betterC unit tests are being tested that they work with -betterC, but at best, it's a soft guarantee, because if there's ever a reason why we need to do something that would not be compatible with -betterC, then the requirement will likely be removed from the unittest block rather than not improving the code. - Jonathan M Davis
Jan 28
prev sibling parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Tuesday, 28 January 2025 at 15:00:13 UTC, Jonathan M Davis 
wrote:
[...]

 -betterC was originally intended to be a tool for making it 
 easier to port C code to D code (after which, the idea was that 
 -betterC would no longer be used, and you would just have a 
 normal D program).
[...]
 - Jonathan M Davis
I thought a further goal of -betterC was to ease D's use in adding further features to existing C programs, by making the linkage effort small. Certainly (though only as a near-trivial hobbyist) I have used -betterC in that way.
Jan 28
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Tuesday, January 28, 2025 10:41:31 AM MST DLearner via Digitalmars-d-learn
wrote:
 On Tuesday, 28 January 2025 at 15:00:13 UTC, Jonathan M Davis
 wrote:
 [...]

 -betterC was originally intended to be a tool for making it
 easier to port C code to D code (after which, the idea was that
 -betterC would no longer be used, and you would just have a
 normal D program).
[...]
 - Jonathan M Davis
I thought a further goal of -betterC was to ease D's use in adding further features to existing C programs, by making the linkage effort small. Certainly (though only as a near-trivial hobbyist) I have used -betterC in that way.
You can use it however you like, and folks have found a variety of uses for it. However, it's a restricted subset of the language that we're not going to support with the standard library precisely because it is so restricted, and the standard library is intended for use with normal D. - Jonathan M Davis
Jan 28
prev sibling next sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Tuesday, 28 January 2025 at 13:01:56 UTC, DLearner wrote:
 Is there a definitive list somewhere of standard library 
 functions that work with -betterC?
basicly none; phoboes causally imports itself and selective imports must parse the whole import still If you make a custom runtime or start deleting sections you can start getting better results, but it would be better if people stopped pretending this was nuanced
Jan 28
prev sibling parent Lance Bachmeier <no spam.net> writes:
On Tuesday, 28 January 2025 at 13:01:56 UTC, DLearner wrote:
 Is there a definitive list somewhere of standard library 
 functions that work with -betterC?

 For example, the following code fragment (taken from the 
 library docs) does not work with -betterC.
 ```
 extern(C) void main() {
    import std.container.array;

    auto arr = Array!int(0, 2, 3);


 }
 ```
I think Mir is compatible with betterC. Maybe some of its functionality will be useful to you. http://mir-algorithm.libmir.org/
Jan 28