digitalmars.D - Cannot compile betterC app in windows using stderr
- Abby (31/31) Feb 01 2022 I have a simple
- forkit (3/3) Feb 01 2022 On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:
- Abby (24/28) Feb 01 2022 Hi did not help
- forkit (13/13) Feb 01 2022 On Wednesday, 2 February 2022 at 06:20:39 UTC, Abby wrote:
- Basile B. (15/46) Feb 01 2022 Yes, I have an idea, although not a Windows user. So look at the
- Basile B. (13/24) Feb 01 2022 Try
- forkit (2/3) Feb 01 2022 nope. won't even compile with -m32 now
- duser (12/36) Feb 02 2022 missing `extern(C)`, it should be:
- forkit (4/15) Feb 02 2022 pls.. not more 'extern's ... I'm seeing 'extern' everywhere now...
- bauss (3/23) Feb 02 2022 extern(C) should imply extern in my book. I'm not sure if it
- Tejas (5/31) Feb 02 2022 Shouldn't `extern` imply `extern(D)` for D?
- Petar Kirov [ZombineDev] (51/54) Feb 02 2022 No, there is a difference between **declaration** and
- kinke (4/16) Feb 02 2022 Nope, they are macros in the MSVC headers, no symbols are
- Abby (3/20) Feb 02 2022 Thank you very much, do you know which lib should be linked and
- Steven Schveighoffer (4/26) Feb 02 2022 Well, looking at the blame for that file, those lines have been there
- Steven Schveighoffer (14/32) Feb 02 2022 I investigated the history of where these are set (in rt/msvc.d), and
- Dennis (5/8) Feb 02 2022 Maybe 2.091 was when dub still defaulted to OMF using the
- Steven Schveighoffer (6/15) Feb 03 2022 I double checked. dub switched to MSCOFF by default [in
- forkit (19/22) Feb 02 2022 but it doesn't work on 2.091 ??
- forkit (3/7) Feb 02 2022 .. I mean specifically on Windows of course.
- forkit (3/3) Feb 02 2022 On Wednesday, 2 February 2022 at 18:57:21 UTC, forkit wrote:
- Steven Schveighoffer (5/19) Feb 02 2022 Dennis is likely correct that it has to do with whether you are using
- Walter Bright (4/22) Feb 02 2022 The trouble is -betterC does not link with druntime, so it can't find st...
- kinke (16/38) Feb 03 2022 That's not a solution, but a hack. ;) - With at least 2 major
- Steven Schveighoffer (4/43) Feb 03 2022 Since pragma inline works now even without the -inline switch, could an
- kinke (4/6) Feb 03 2022 Nope, sadly not - the problem is `&stderr` returning a function
- Steven Schveighoffer (4/10) Feb 03 2022 Ugh, yep. Damn us for not correctly implementing @property.
- Tejas (9/20) Feb 03 2022 What will it take to implement `@property` correctly? What is it
- Steven Schveighoffer (25/38) Feb 04 2022 What @property *should* have done (it's very limited in functionality
- Steven Schveighoffer (9/20) Feb 12 2022 Was going to post about this on Rainer's PR to fix this issue, but as it...
- Walter Bright (7/18) Feb 03 2022 "Header only" libraries work well for C++. We can make it work for D. In...
I have a simple **dub.sdl** ``` name "test" targetType "executable" buildOptions "betterC" ``` **app.d** ``` module test; import core.stdc.stdio : fprintf, stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ``` When I'm trying to compile this on windows with latest dmd or ldc I get ```Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. test ~master: building configuration "application"... Linking... test.obj : error LNK2019: unresolved external symbol stderr referenced in function main .dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-FB5231E74956BBA34BF96 F450A8342C\test.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. ``` Works with dmd-2.091.0 Any idea what might be the problem here?
Feb 01 2022
On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:a link error with the 64bit version of dmd ?? try: -m32
Feb 01 2022
On Wednesday, 2 February 2022 at 03:34:29 UTC, forkit wrote:On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:Hi did not help ``` dub build --arch=x86_64 The following compiler flags have been specified in the package description file. They are handled by DUB and direct use in packages is discouraged. Alternatively, you can set the DFLAGS environment variable to pass custom flags to the compiler, or use one of the suggestions below: -m32: Use --arch=x86/--arch=x86_64/--arch=x86_mscoff to specify the target architecture, e.g. 'dub build --arch=x86_64' Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. test ~master: building configuration "application"... Linking... test.obj : error LNK2019: unresolved external symbol stderr referenced in function main .dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-ED981EB8716B85E9E2580 86FAF4E89B\test.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. ```a link error with the 64bit version of dmd ?? try: -m32
Feb 01 2022
On Wednesday, 2 February 2022 at 06:20:39 UTC, Abby wrote:I don't know about dub. never used it. I can say, that your code will compile and run fine if compiled with dmd using: dmd -m32 -betterC mycode.d but not dmd -m64 -betterC mycode.d it seems like a MSVC linking error (possibly unresolved references or something). Also, this is a Windows issue. The same code will compile fine on linux -32 or -m64 Someone with more expertise will need to troubleshoot this further ;-)
Feb 01 2022
On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:I have a simple **dub.sdl** ``` name "test" targetType "executable" buildOptions "betterC" ``` **app.d** ``` module test; import core.stdc.stdio : fprintf, stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ``` When I'm trying to compile this on windows with latest dmd or ldc I get ```Performing "debug" build using C:\D\dmd2\windows\bin64\dmd.exe for x86_64. test ~master: building configuration "application"... Linking... test.obj : error LNK2019: unresolved external symbol stderr referenced in function main .dub\build\application-debug-windows-x86_64-dmd_v2.098.1-dirty-FB5231E74956BBA34BF96 F450A8342C\test.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. ``` Works with dmd-2.091.0 Any idea what might be the problem here?Yes, I have an idea, although not a Windows user. So look at the definitions i `core.stdc.stdio`: ```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?
Feb 01 2022
On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:Try ```d module test; import core.stdc.stdio : FILE, fprintf; extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ``` to confirm if it is or not the extern problemI have a simple **dub.sdl** ``` name "test" targetType "executable" buildOptions "betterC" ```shouldn't these variable declarations be `extern` ?
Feb 01 2022
On Wednesday, 2 February 2022 at 07:51:07 UTC, Basile B. wrote:extern shared FILE* stderr;nope. won't even compile with -m32 now
Feb 01 2022
On Wednesday, 2 February 2022 at 07:51:07 UTC, Basile B. wrote:On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:missing `extern(C)`, it should be: ```D module test; import core.stdc.stdio : FILE, fprintf; extern(C) extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ```On Wednesday, 2 February 2022 at 01:24:30 UTC, Abby wrote:Try ```d module test; import core.stdc.stdio : FILE, fprintf; extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ``` to confirm if it is or not the extern problemI have a simple **dub.sdl** ``` name "test" targetType "executable" buildOptions "betterC" ```shouldn't these variable declarations be `extern` ?
Feb 02 2022
On Wednesday, 2 February 2022 at 09:27:02 UTC, duser wrote:missing `extern(C)`, it should be: ```D module test; import core.stdc.stdio : FILE, fprintf; extern(C) extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ```pls.. not more 'extern's ... I'm seeing 'extern' everywhere now... ..I'm gunna puke if I see another one. and no, that doesn't work either :-(
Feb 02 2022
On Wednesday, 2 February 2022 at 10:53:56 UTC, forkit wrote:On Wednesday, 2 February 2022 at 09:27:02 UTC, duser wrote:extern(C) should imply extern in my book. I'm not sure if it does, but it seems wrong if it doesn't.missing `extern(C)`, it should be: ```D module test; import core.stdc.stdio : FILE, fprintf; extern(C) extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ```pls.. not more 'extern's ... I'm seeing 'extern' everywhere now... ..I'm gunna puke if I see another one. and no, that doesn't work either :-(
Feb 02 2022
On Wednesday, 2 February 2022 at 11:46:47 UTC, bauss wrote:On Wednesday, 2 February 2022 at 10:53:56 UTC, forkit wrote:Shouldn't `extern` imply `extern(D)` for D? In C, `extern` implies `extern "C"` In C++, `extern` implies `extern "C++"` Why different behaviour for D?On Wednesday, 2 February 2022 at 09:27:02 UTC, duser wrote:extern(C) should imply extern in my book. I'm not sure if it does, but it seems wrong if it doesn't.missing `extern(C)`, it should be: ```D module test; import core.stdc.stdio : FILE, fprintf; extern(C) extern shared FILE* stderr; extern(C) int main(string[] args) { fprintf(stderr, "Test\n",); return 0; } ```pls.. not more 'extern's ... I'm seeing 'extern' everywhere now... ..I'm gunna puke if I see another one. and no, that doesn't work either :-(
Feb 02 2022
On Wednesday, 2 February 2022 at 11:46:47 UTC, bauss wrote:[..] extern(C) should imply extern in my book. I'm not sure if it does, but it seems wrong if it doesn't.No, there is a difference between **declaration** and **definition** at the linker level. `extern (C|C++|C|Objective-C|Windows|System)` sets the mangling of a variable declaration or definition. `extern` changes a variable definition to a declaration. Check the following cases: ```d import core.stdc.stdio : FILE, printf, fprintf; shared FILE* stderr; // 1. // extern (D) shared FILE* stderr; // 2. // extern (C) shared FILE* stderr; // 3. // extern shared FILE* stderr; // 4. // extern extern (C) shared FILE* stderr; // 5. pragma (msg, stderr.mangleof, "\n"); void main() { if (stderr) fprintf(stderr, "stderr exists.\n"); else printf("stderr doesn't exist.\n"); } ``` 1. `shared FILE* stderr;` -> A global variable `stderr` **declared** and **defined** in the current module with D linkage * Compiles and links ok. * Prints `_D9onlineapp6stderrOPS4core4stdc5stdio8_IO_FILE` at compile-time. * Prints `stderr doesn't exist.` at run-time. 2. `extern (D) shared FILE* stderr;` -> Same as above - `extern (D)` is the default linkage. 3. `extern (C) shared FILE* stderr;` -> A global variable `stderr` **declared** and **defined** in the current module with C linkage * Compiles and links ok. * Prints `stderr` at compile-time. * Prints `stderr doesn't exist.` at run-time. 4. `extern shared FILE* stderr;` -> A global variable `stderr` **declared** but **not defined** in the current module with D linkage. It has to be defined in another module (library) * Compiles ok, but fails to link. * Prints `_D9onlineapp6stderrOPS4core4stdc5stdio8_IO_FILE` at compile-time. * Doesn't run 6. `extern extern (C) shared FILE* stderr;` -> A global variable `stderr` **declared** but **not defined** in the current module with C linkage. It has to be defined in another module (library) * Compiles and links ok (the compiler/linker driver automatically links libc). * Prints `stderr` at compile-time. * Prints `stderr exists.` at run-time.
Feb 02 2022
On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 02 2022
On Wednesday, 2 February 2022 at 12:17:01 UTC, kinke wrote:On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:Thank you very much, do you know which lib should be linked and why it all works in dmd-2.091.0?```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 02 2022
On 2/2/22 8:16 AM, Abby wrote:On Wednesday, 2 February 2022 at 12:17:01 UTC, kinke wrote:Well, looking at the blame for that file, those lines have been there for 10 years, so that isn't the reason for the change. -SteveOn Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:Thank you very much, do you know which lib should be linked and why it all works in dmd-2.091.0?```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 02 2022
On 2/2/22 7:17 AM, kinke wrote:On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:I investigated the history of where these are set (in rt/msvc.d), and it's fascinating. I'm not sure why it works on 2.091, though, this setup has existed since at least 2015, and probably before. See this PR: https://github.com/dlang/druntime/pull/1360 It was changed from a c file to a d file in October 2020 (see https://github.com/dlang/druntime/pull/3223), maybe that has something to do with it? Though it still shouldn't be running the init_msvc function in -betterC, even in 2.091 (which was released before this change). I tend to believe that maybe the OP is mistaken that it works, or there was a latent bug that was still running some of druntime that has been fixed. -Steve```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 02 2022
On Wednesday, 2 February 2022 at 14:38:49 UTC, Steven Schveighoffer wrote:I tend to believe that maybe the OP is mistaken that it works, or there was a latent bug that was still running some of druntime that has been fixed.Maybe 2.091 was when dub still defaulted to OMF using the DigitalMars runtime, and it just seems to work since it's not using the Windows runtime.
Feb 02 2022
On 2/2/22 12:19 PM, Dennis wrote:On Wednesday, 2 February 2022 at 14:38:49 UTC, Steven Schveighoffer wrote:I double checked. dub switched to MSCOFF by default [in 2.086](https://dlang.org/changelog/2.086.0.html#dmd-mscoff-default). Though it's possible the user is using a different version of dub. Only way to be sure is to do a clean install and try it on Windows. -SteveI tend to believe that maybe the OP is mistaken that it works, or there was a latent bug that was still running some of druntime that has been fixed.Maybe 2.091 was when dub still defaulted to OMF using the DigitalMars runtime, and it just seems to work since it's not using the Windows runtime.
Feb 03 2022
On Wednesday, 2 February 2022 at 14:38:49 UTC, Steven Schveighoffer wrote:I'm not sure why it works on 2.091, though, this setup has existed since at least 2015, and probably before. See this PR: https://github.com/dlang/druntime/pull/1360but it doesn't work on 2.091 ?? how this has escaped the testing process ..is..well..kinda disturbing. This code below, will not compile using these parameters: -m64 -betterC but WILL using -m32 -betterC // --- module test; import core.stdc.stdio; extern (C): int main(int argc,char** argv) { fprintf(stderr, "grr!\n"); return 0; } // -----
Feb 02 2022
On Wednesday, 2 February 2022 at 18:51:04 UTC, forkit wrote:This code below, will not compile using these parameters: -m64 -betterC but WILL using -m32 -betterC.. I mean specifically on Windows of course. It's fine on linux.
Feb 02 2022
On Wednesday, 2 February 2022 at 18:57:21 UTC, forkit wrote:if only godbolt supported D on it's MSVC compilers :-( https://www.godbolt.ms/
Feb 02 2022
On 2/2/22 1:57 PM, forkit wrote:On Wednesday, 2 February 2022 at 18:51:04 UTC, forkit wrote:Dennis is likely correct that it has to do with whether you are using MSVC libc or DMC libc. I was going to look further, but github seems to be down. -SteveThis code below, will not compile using these parameters: -m64 -betterC but WILL using -m32 -betterC.. I mean specifically on Windows of course. It's fine on linux.
Feb 02 2022
On 2/2/2022 4:17 AM, kinke wrote:On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 02 2022
On Wednesday, 2 February 2022 at 20:58:25 UTC, Walter Bright wrote:On 2/2/2022 4:17 AM, kinke wrote:That's not a solution, but a hack. ;) - With at least 2 major problems: * Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway. * Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process. There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 03 2022
On 2/3/22 2:55 PM, kinke wrote:On Wednesday, 2 February 2022 at 20:58:25 UTC, Walter Bright wrote:Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro? -SteveOn 2/2/2022 4:17 AM, kinke wrote:That's not a solution, but a hack. ;) - With at least 2 major problems: * Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway. * Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process. There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)On Wednesday, 2 February 2022 at 07:33:58 UTC, Basile B. wrote:The trouble is -betterC does not link with druntime, so it can't find stderr. The solution is to make stderr a template, so that no linking with druntime is necessary.```d else version (CRuntime_Microsoft) { /// shared FILE* stdin; // = &__iob_func()[0]; /// shared FILE* stdout; // = &__iob_func()[1]; /// shared FILE* stderr; // = &__iob_func()[2]; } ``` shouldn't these variable declarations be `extern` ?Nope, they are macros in the MSVC headers, no symbols are available. That's why druntime defines them and sets them up at startup, so they aren't available/linked with `-betterC`.
Feb 03 2022
On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?Nope, sadly not - the problem is `&stderr` returning a function pointer then, not the address of the symbol directly.
Feb 03 2022
On 2/3/22 5:13 PM, kinke wrote:On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:Ugh, yep. Damn us for not correctly implementing property. Would be the same problem with a template as well. -SteveSince pragma inline works now even without the -inline switch, could an inline function take the place of the macro?Nope, sadly not - the problem is `&stderr` returning a function pointer then, not the address of the symbol directly.
Feb 03 2022
On Friday, 4 February 2022 at 00:54:50 UTC, Steven Schveighoffer wrote:On 2/3/22 5:13 PM, kinke wrote:What will it take to implement ` property` correctly? What is it that we're lacking? I genuinely don't understand anything about this particular topic: what is preventing us from fixing this particular part of the language even though it crops up pretty frequently? Could you maybe please link me to a forum post where this has been discussed?On Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:Ugh, yep. Damn us for not correctly implementing property. Would be the same problem with a template as well. -SteveSince pragma inline works now even without the -inline switch, could an inline function take the place of the macro?Nope, sadly not - the problem is `&stderr` returning a function pointer then, not the address of the symbol directly.
Feb 03 2022
On 2/3/22 11:13 PM, Tejas wrote:On Friday, 4 February 2022 at 00:54:50 UTC, Steven Schveighoffer wrote:What property *should* have done (it's very limited in functionality now, and not likely to be fixed) is to disable accessing via the function at all. The fact that it's a function call should be an implementation detail. in other words: ```d int _x; property ref int x() { return _x;} static assert(is(typeof(x) == int)); // this is true today static assert(typeof(&x) == int *)); // this is not true but should be auto y = x(); // should not compile, but does, an int is not a function. ``` If this were the case, then fixing the stderr problem mentioned here would be possible using properties.Ugh, yep. Damn us for not correctly implementing property. Would be the same problem with a template as well.What will it take to implement ` property` correctly? What is it that we're lacking?I genuinely don't understand anything about this particular topic: what is preventing us from fixing this particular part of the language even though it crops up pretty frequently? Could you maybe please link me to a forum post where this has been discussed?The property debate is really old. When it was added, the thought was to get rid of some of these sticky corner cases. D has had property *syntax* since D1. But the property attribute was supposed to be a way to declare "this is a property, so it shouldn't behave like a function". But core members disliked the added complications, and so the benefits of property were kind of cancelled. There are a few draft DIPS on it (from the old system in the wiki, see here: https://wiki.dlang.org/DIPs). Now we are just left with a really obscure difference (the typeof difference) which is IMO confusing anyway. -Steve
Feb 04 2022
On 2/3/22 7:54 PM, Steven Schveighoffer wrote:On 2/3/22 5:13 PM, kinke wrote:Was going to post about this on Rainer's PR to fix this issue, but as it turns out, none of this matters -- on Windows, `stderr` is a constant, and in fact the return value from a function. So `&stderr` isn't valid, and the fact that it currently works is not actually correct. In fact, in D currently you can set `stderr` to something else, and it won't apply to the C side, which is really bad. And as a template function, `&stderr` is a compiler error anyway. -SteveOn Thursday, 3 February 2022 at 21:56:27 UTC, Steven Schveighoffer wrote:Ugh, yep. Damn us for not correctly implementing property. Would be the same problem with a template as well.Since pragma inline works now even without the -inline switch, could an inline function take the place of the macro?Nope, sadly not - the problem is `&stderr` returning a function pointer then, not the address of the symbol directly.
Feb 12 2022
On 2/3/2022 11:55 AM, kinke wrote:* Template culling. If the compiler e.g. sees a stderr instantiation in druntime in the import graph, it may decide not to emit the stderr symbol into the betterC binary, assuming that druntime will be linked anyway. * Potentially a DSO-local stderr symbol for each binary (executable or DLL/.so/.dylib), so that changing it in one DSO might not change it for the whole process. There have been previous 'dummy-templatizations' in druntime/Phobos to work around missing symbols with -betterC. IMO, that's just patching over the cracks of the -betterC hack and pessimizing regular D, and in case it's not obvious, I'm definitely no fan of this. :)"Header only" libraries work well for C++. We can make it work for D. In fact, we have to. As for stderr, it should never be an instance of the iob itself. That instance resides only in the C stdlib. stderr should only be an indirect reference to it, hence multiple instances of stderr should work just fine. With a bit of careful library design, we can make this work.
Feb 03 2022