DMD 2.109.1 -betterC under Windows 10

The code below executes correctly:


```
extern (C) void main() {

   import core.stdc.stdio : printf;

   size_t wkIdx;
   size_t wkPos;

   enum Count = 1;

   struct OpVar {
      void*  Addr;
      int    Type;
   }

   OpVar[Count] OpVars;

   int IntVar1 = 5;


   OpVars[0].Addr = &IntVar1;
   OpVars[0].Type = 1;

   for (wkPos = 1; wkPos <= OpVars.length; wkPos = wkPos + 1) {
      wkIdx = wkPos - 1;

printf("Value = %d \n", *(cast(int*)(OpVars[wkIdx].Addr)));
   }
}

```


However, the code below, changing the Type variable to char:

```
extern (C) void main() {

   import core.stdc.stdio : printf;

   size_t wkIdx;
   size_t wkPos;

   enum Count = 1;

   struct OpVar {
      void*  Addr;
      char   Type;
   }

   OpVar[Count] OpVars;

   int IntVar1 = 5;


   OpVars[0].Addr = &IntVar1;
   OpVars[0].Type = '1';

   for (wkPos = 1; wkPos <= OpVars.length; wkPos = wkPos + 1) {
      wkIdx = wkPos - 1;

printf("Value = %d \n", *(cast(int*)(OpVars[wkIdx].Addr)));
   }
}


```

fails with:

```

addrtest.obj : error LNK2019: unresolved external symbol _memsetn referenced in function main
addrtest.exe : fatal error LNK1120: 1 unresolved externals
Error: linker exited with status 1120
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64\link.exe /NOLOGO "addrtest.obj" /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\um\x64"
Error: undefined reference to `_memsetn`
       referenced from `main`
perhaps a library needs to be added with the `-L` flag or `pragma(lib, ...)`
```

  • Bug in DMD bette... DLearner via Digitalmars-d-learn
    • Re: Bug in ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn

Reply via email to