Bug in DMD betterC?

DLearner bmqazwsx123 at gmail.com
Fri Jan 24 20:21:16 UTC 2025


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, ...)`
```



More information about the Digitalmars-d-learn mailing list