Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
April 25, 2019 DMD different compiler behaviour on Linux and Windows | ||||
---|---|---|---|---|
| ||||
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. |
April 25, 2019 Re: DMD different compiler behaviour on Linux and Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zans | 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.
The issue here is not Windows vs Linux but 32 bits vs 64 bits.
On 32 bits architectures size_t is defined as uint, long being 64 bits long, conversion from long to uint is a truncating cast which are not allowed implicitely in D.
It is unfortunate that the D compiler on Windows is still delivered by default as a 32 bits binary and generating 32 bits code. I think the next release will start to deliver the compiler as 64 bits binary and generating 64 bits code.
|
April 25, 2019 Re: DMD different compiler behaviour on Linux and Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zans | 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.
|
April 26, 2019 Re: DMD different compiler behaviour on Linux and Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Thursday, 25 April 2019 at 20:38:31 UTC, Mike Parker wrote:
> If you compile with -m32 on Windows the error goes away.
Not trying to be a <clever donkey> but it also works with -m64 on Windows.
|
April 26, 2019 Re: DMD different compiler behaviour on Linux and Windows | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ron Tarrant | On Friday, 26 April 2019 at 15:48:51 UTC, Ron Tarrant wrote:
> On Thursday, 25 April 2019 at 20:38:31 UTC, Mike Parker wrote:
>> If you compile with -m32 on Windows the error goes away.
>
> Not trying to be a <clever donkey> but it also works with -m64 on Windows.
Yes, thanks. That's a typo. -m32, where size_t is uint, is the default. In -m64, size_t is ulong.
|
Copyright © 1999-2021 by the D Language Foundation