www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why .length on Windows is int and on Linux is ulong?

reply Suliman <evermind live.ru> writes:
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?
Feb 29 2016
next sibling parent Rikki Cattermole <alphaglosined gmail.com> writes:
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.
Feb 29 2016
prev sibling parent ag0aep6g <anonymous example.com> writes:
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
Feb 29 2016