On Thursday, 25 April 2019 at 20:18:28 UTC, Zans wrote:
import std.stdio;

void main()
{
    char[] mychars;
    mychars ~= 'a';
    long index = 0L;
    writeln(mychars[index]);
}

Why would the code above compile perfectly on Linux (Ubuntu 16.04), however it would produce the following error on Windows 10:

source\app.d(8,21): Error: cannot implicitly convert expression index of type long to uint

On both operating systems DMD version is 2.085.0.

DMD defaults to 64-bit output on 64-Bit Linux but always to 32-bit output on Windows, If you compile with -m32 on Windows the error goes away. Reasons::

* Array indices are default typed as size_t, which is uint in 32-bit and ulong in 64. long is not implicitly convertible to uint.

* On Linux, both 64- and 32-bit builds of DMD are available and the output for each defaults to the same. Only the 32-bit build is distributed on Windows.

* Historically, compiling 64-bit binaries on Windows required a separate installation of the Microsoft Build Tools ( or Visual Studio) and/or the Windows SDK. If 64-bit output were the default, DMD would not work out of the box. Recently, DMD has been shipping with the lld linker and some MinGW-based Windows libraries so that the additional installation is not required and 64-bit compiles can work out of the box, but it’s still considered experimental.

When out-of-the-box 64-bit compilation is solid and 64-bit builds are distributed on Windows, the default behavior should be the same as on Linux.

Reply via email to