April 04
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.
April 03
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 sure you are correct, but extern(C) -> extern(D) in both references.
So both source streams are aware of the convention used.
April 03
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 same data.
Without `extern (C)` (or with `extern (D)`), they are distinct variables with no relation to another. In D, you don't re-declare another module's symbols. You import the other module.

----
module testmain;

import std.stdio: writeln;
import testmod: testsub, xvar;

void main()
{
    xvar = 1;
    writeln(xvar); /* prints "1" */
    testsub();
    writeln(xvar); /* prints "2" */
}
----

----
module testmod;

int xvar; /* same as `extern (D) int xvar;` */

void testsub()
{
   xvar = 2;
}
----
April 04
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 incorporates things like the module name.
> 
> I'm sure you are correct, but extern(C) -> extern(D) in both references.
> So both source streams are aware of the convention used.

https://dlang.org/spec/abi.html#name_mangling
April 03
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) int xvar;
>
> With `extern (C)`, those two `xvar`s refer to the same data.
> Without `extern (C)` (or with `extern (D)`), they are distinct variables with no relation to another. In D, you don't re-declare another module's symbols. You import the other module.
>
> ----
> module testmain;
>
> import std.stdio: writeln;
> import testmod: testsub, xvar;
>
> void main()
> {
>     xvar = 1;
>     writeln(xvar); /* prints "1" */
>     testsub();
>     writeln(xvar); /* prints "2" */
> }
> ----
>
> ----
> module testmod;
>
> int xvar; /* same as `extern (D) int xvar;` */
>
> void testsub()
> {
>    xvar = 2;
> }
> ----

Thank you, your suggestions worked.
No externs anywhere.
For the record, the code is below.
import itf;
import testmod:testsub;
void main() {
   import std.stdio;

   writeln("Entering: main");
   xvar = 1;
   writeln("xvar=", xvar);
   testsub();
   writeln("xvar=", xvar);

   writeln("Leaving: main");
}

module itf;
int xvar;

module testmod;
import itf;
void testsub() {

   import std.stdio;

   writeln("Entering: testsub");
   writeln("xvar=", xvar);
   xvar = 2;
   writeln("xvar=", xvar);
   writeln("Leaving: testsub");
}





Next ›   Last »
1 2