On Saturday, 3 April 2021 at 13:50:27 UTC, ag0aep6g wrote:
On 03.04.21 15:34, DLearner wrote:
The following produces the expected result.
However, changing extern(C) to extern(D) causes linker
failures.
To me, that is bizarre.
Testmain:
extern(C) int xvar;
[...]
Testmod:
extern extern(C)
On 04/04/2021 2:48 AM, DLearner wrote:
On Saturday, 3 April 2021 at 13:38:25 UTC, rikki cattermole wrote:
On 04/04/2021 2:34 AM, DLearner wrote:
However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.
extern(D) sets the ABI AND mangling.
D mangling
On 03.04.21 15:34, DLearner wrote:
The following produces the expected result.
However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.
Testmain:
extern(C) int xvar;
[...]
Testmod:
extern extern(C) int xvar;
With `extern (C)`, those two `xvar`s refer to the
On Saturday, 3 April 2021 at 13:38:25 UTC, rikki cattermole wrote:
On 04/04/2021 2:34 AM, DLearner wrote:
However, changing extern(C) to extern(D) causes linker
failures.
To me, that is bizarre.
extern(D) sets the ABI AND mangling.
D mangling incorporates things like the module name.
I'm
On 04/04/2021 2:34 AM, DLearner wrote:
However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.
extern(D) sets the ABI AND mangling.
D mangling incorporates things like the module name.
The __gshared is irrelevant to it working between modules, but
it is relevant if you want C compatibility between threads
(NOTE: extern(C) sets mangling, otherwise the module would be
encoded in its name).
Solved:
The following produces the expected result.
However, changing extern(C) to
--- main.d
module main;
extern(C) __gshared int foo;
import std;
void main()
{
import foo : func;
func;
writeln(foo);
}
--- foo.d
module foo;
extern extern(C) __gshared int foo;
void func() {
foo++;
}
The __gshared is irrelevant to it working between modules, but it is
https://dlang.org/spec/attribute.html#gshared
However, you should be using the module system for accessing
globals, rather than redeclaring them.
If the module system is dumped, and evrything put into one file,
works perfectly.
With or without __gshared in from of 'int xvar'.
int xvar;
extern(L) extern otherQualifiersIfAny variableType
variableName; //appears to be a variable declared outside of
the module, so at link time a .obj file will have to declare a
variable with this symbol name or else the linker will error
out.
```
It seems that case 4 is what you desired but i
Tried the following, same result (1,0,2,1):
testmain:
__gshared int xvar;
import testmod;
void main() {
import std.stdio;
writeln("Entering: main");
xvar = 1;
writeln("xvar=", xvar);
testsub();
writeln("xvar=", xvar);
writeln("Leaving: main");
}
testmod:
void testsub() {
On Saturday, 3 April 2021 at 10:17:14 UTC, DLearner wrote:
Does this mean D has no equivalent of C globals?
What is the D way of doing this?
With __gshared.
If the global is defined from within another language, apparently
you'd have to do [extern(C) extern __gshared
On 03/04/2021 11:17 PM, DLearner wrote:
On Saturday, 3 April 2021 at 10:05:45 UTC, rikki cattermole wrote:
On 03/04/2021 11:01 PM, DLearner wrote:
[...]
TLS variable with D mangling, not a c global.
[...]
That is a regular variable.
Setting the calling convention/mangling like that
On Saturday, 3 April 2021 at 10:05:45 UTC, rikki cattermole wrote:
On 03/04/2021 11:01 PM, DLearner wrote:
[...]
TLS variable with D mangling, not a c global.
[...]
That is a regular variable.
Setting the calling convention/mangling like that doesn't make
any sense and shouldn't be
On 03/04/2021 11:01 PM, DLearner wrote:
'Testmain' imports module 'testmod'.
Both are shown below.
I expected 1,1,2,2.
I got 1,0,2,1 - which speaks to scope/extern misunderstanding
Any ideas?
Best regards
Testmain:
int xvar;
TLS variable with D mangling, not a c global.
import testmod;
'Testmain' imports module 'testmod'.
Both are shown below.
I expected 1,1,2,2.
I got 1,0,2,1 - which speaks to scope/extern misunderstanding
Any ideas?
Best regards
Testmain:
int xvar;
import testmod;
void main() {
import std.stdio;
writeln("Entering: main");
xvar = 1;
15 matches
Mail list logo