Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 12, 2017 [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 Илья Ярошенко <ilyayaroshenko@gmail.com> --- And extern(C++), extern(D) can/should work too. -- |
August 13, 2017 [Issue 17747] extern(C) shared static module constructor should be called in betterC programs | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=17747 ZombineDev <petar.p.kirov@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |betterC, C++ CC| |petar.p.kirov@gmail.com --- Comment #2 from ZombineDev <petar.p.kirov@gmail.com> --- 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. -- |
August 14, 2017 [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 Илья Ярошенко <ilyayaroshenko@gmail.com> --- (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. -- |
August 27, 2017 [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 <petar.p.kirov@gmail.com> --- > __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. -- |
August 27, 2017 [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 <petar.p.kirov@gmail.com> --- > It can be called in start before main, without DRuntime. Agreed. -- |
September 13, 2017 [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 <schveiguy@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |schveiguy@yahoo.com Severity|blocker |enhancement --- Comment #6 from Steven Schveighoffer <schveiguy@yahoo.com> --- 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. -- |
September 14, 2017 [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 <dfj1esp02@sneakemail.com> --- (In reply to Steven Schveighoffer from comment #6) > D static ctors C abi is requested with extern(C) here, sure they are different. -- |
September 14, 2017 [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 <schveiguy@yahoo.com> --- (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. -- |
September 18, 2017 [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 <dfj1esp02@sneakemail.com> --- (In reply to Steven Schveighoffer from comment #8) > People are used to this "just working". Same problem for other usage of extern(C). -- |
September 18, 2017 [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 <schveiguy@yahoo.com> --- (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. -- |
Copyright © 1999-2021 by the D Language Foundation