Thread overview
Why .length on Windows is int and on Linux is ulong?
Feb 29, 2016
Suliman
Feb 29, 2016
Rikki Cattermole
Feb 29, 2016
ag0aep6g
February 29, 2016
On Windows next code work fine:
int len = fullimgurl.length;

On Linux DMD get error that:
Error: cannot implicitly convert expression (fullimgurl.length) of type ulong to int

Why on every OS length have different size?

March 01, 2016
On 01/03/16 12:06 AM, Suliman wrote:
> On Windows next code work fine:
> int len = fullimgurl.length;
>
> On Linux DMD get error that:
> Error: cannot implicitly convert expression (fullimgurl.length) of type
> ulong to int
>
> Why on every OS length have different size?

Its not OS dependent, its arch dependent.
On Windows you are building in 32bit mode but on Linux 64bit.

February 29, 2016
On 29.02.2016 12:06, Suliman wrote:
> On Windows next code work fine:
> int len = fullimgurl.length;
>
> On Linux DMD get error that:
> Error: cannot implicitly convert expression (fullimgurl.length) of type
> ulong to int
>
> Why on every OS length have different size?

On Windows, the compiler flag -m32 is the default, regardless of dmd's bitness [1]; on Linux it's -m64 for 64 bit dmd [2]. That's what causes the different sizes. Use size_t for lengths, not int or ulong or any other specifically sized type.

By the way, with -m32, size_t is uint, not int.


[1] http://dlang.org/dmd-windows.html#switch-m32
[2] http://dlang.org/dmd-linux.html#switch-m64