[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 Walter Bright changed: What|Removed |Added Status|NEW |RESOLVED CC||bugzi...@digitalmars.com Resolution|--- |FIXED --- Comment #18 from Walter Bright --- resolved by https://github.com/dlang/dmd/pull/7182 --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 Martin Nowak changed: What|Removed |Added Keywords||pull CC||c...@dawg.eu --- Comment #17 from Martin Nowak --- Walters take on this was to simply run `shared static ctors/dtors` in betterC. https://github.com/dlang/dmd/pull/6956 --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 anonymous4 changed: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=17868 --- Comment #16 from anonymous4 --- Issue 17868 - proposal with priorities. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #15 from anonymous4 --- (In reply to Steven Schveighoffer from comment #14) > Changing the link order does nothing, because there is one file. It requires two files to work. > In other words, issue 7063 is a bug, no matter how you build it. It > shouldn't build (hence accepts-invalid). But for D abi it would build and just work. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #14 from Steven Schveighoffer --- Changing the link order does nothing, because there is one file. In other words, issue 7063 is a bug, no matter how you build it. It shouldn't build (hence accepts-invalid). This proposal is different -- if you link in one order, it will work as expected. Change that order, and it will blow up. IMO, we should not introduce this kind of problem. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #13 from anonymous4 --- Looks like it. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #12 from Steven Schveighoffer --- (In reply to anonymous4 from comment #11) > (In reply to Steven Schveighoffer from comment #10) > > There is also no other precedent where a compiled D program only works > > properly if you link in the correct order. > > Issue 7063 So that program works properly if you link in a different order? --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #11 from anonymous4 --- (In reply to Steven Schveighoffer from comment #10) > There is also no other precedent where a compiled D program only works > properly if you link in the correct order. Issue 7063 --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #10 from Steven Schveighoffer --- (In reply to anonymous4 from comment #9) > (In reply to Steven Schveighoffer from comment #8) > > People are used to this "just working". > Same problem for other usage of extern(C). How so? void foo(); extern(C) void foo(); What is the difference? Don't both work exactly the same? As far as I know, the only difference is mangling. There is also no other precedent where a compiled D program only works properly if you link in the correct order. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #9 from anonymous4 --- (In reply to Steven Schveighoffer from comment #8) > People are used to this "just working". Same problem for other usage of extern(C). --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #8 from Steven Schveighoffer --- (In reply to anonymous4 from comment #7) > C abi is requested with extern(C) here, sure they are different. Essentially, what I'm saying is: mod1.d: int x; extern(C) static this() { x = 5; } mod2.d: import mod1; int y; extern(C) static this() { y = x + 1; // should be 6, but could be 1 if executed in the wrong order } Druntime knows how to make this work. C does not. You are changing the semantic meaning of static this() by putting an extern(C) on it, and I don't think it's a good idea. People are used to this "just working". You also likely will break code, as I think there are many files with extern(C): at the top, for which this would change the semantics. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #7 from anonymous4 --- (In reply to Steven Schveighoffer from comment #6) > D static ctors C abi is requested with extern(C) here, sure they are different. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 Steven Schveighoffer changed: What|Removed |Added CC||schvei...@yahoo.com Severity|blocker |enhancement --- Comment #6 from Steven Schveighoffer --- How is the order determined? D static ctors are written assuming the import graph can be used to deduce a valid ordering of calls. If this were to be implemented, an extern(C) static ctor would have a completely different meaning. I would be against this. In any case, this is an enhancement, not a blocker. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #5 from ZombineDev --- > It can be called in start before main, without DRuntime. Agreed. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #4 from ZombineDev --- > __attribute__ ((constructor)) is in C. It can be called in start before main, > without DRuntime. Technically this is a compiler extension, not a feature part of the ISO C standard. My point was that C standard does not require such feature and therefore we shouldn't rely on its existence. On the other hand, C++ does due to the need to be able to call class constructors for static/global variables. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #3 from Илья Ярошенко --- (In reply to ZombineDev from comment #2) > AFAIK, C doesn't have static constructors, only C++ has, so your example > should be: > > extern(C++) shared static this() > { > // ... > } > > Of course extern (D) should work too: > > extern(D) shared static this() > { > // ... > } > > I'm not sure if `pragma(mangle, ...) [shared] static this()` should be > allowed as static constructors / destructors are meant to be called only > once and only by the runtime. __attribute__ ((constructor)) is in C. It can be called in start before main, without DRuntime. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 ZombineDev changed: What|Removed |Added Keywords||betterC, C++ CC||petar.p.ki...@gmail.com --- Comment #2 from ZombineDev --- AFAIK, C doesn't have static constructors, only C++ has, so your example should be: extern(C++) shared static this() { // ... } Of course extern (D) should work too: extern(D) shared static this() { // ... } I'm not sure if `pragma(mangle, ...) [shared] static this()` should be allowed as static constructors / destructors are meant to be called only once and only by the runtime. --
[Issue 17747] extern(C) shared static module constructor should be called in betterC programs
https://issues.dlang.org/show_bug.cgi?id=17747 --- Comment #1 from Илья Ярошенко --- And extern(C++), extern(D) can/should work too. --