Why .length on Windows is int and on Linux is ulong?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 29 03:13:48 PST 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


More information about the Digitalmars-d-learn mailing list