windows64/linux64 Error: cannot implicitly convert expression of type ulong to int

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Mon Feb 18 19:55:15 PST 2013


On Tue, 19 Feb 2013 03:13:14 +0000 (GMT)
Anastasios Tsiolakidis <abstractius at yahoo.co.uk> wrote:

> Hello,
> 
> this is perhaps something for d.learning, except that I don't see
> how! I found a small D program on Facebook
> http://pastebin.ca/2315433 , and compiling it with all 3
> implementations on my Ubuntu 12.10 gives this "common" eror, in 2
> implementations with more verbose output
> 
> 
> h3.d(72): Error: cannot implicitly convert expression (g0.length) of
> type ulong to int
> 
> 
> On Windows 7-64 however it compiles just fine with dmd2. From a
> discussion on this list I concluded this error is "fundamental" and
> don't expect it to be configurable with a compiler switch or
> whatever. Nor do I expect the dmd package to ship with fundamentally
> different config files on windows and linux. What's going on? Thanks
> 
> AT
> 

Line 72 should be:

size_t n = g0.length;

or just:

auto n = g0.length; // Automatically infer the correct type

There may be some other int's that should be size_t as well.

This is because array lengths are size_t: the unsigned native word size
of the system. 32-bit (ie uint) on 32-bit systems, and 64-bit (ie
ulong) on 64-bit systems.

Although it sounds like a bug that Win64 *isn't* giving you an error.
(D's Win64 support is much newer than Linux64). Really, it's arguable
that it should even be an error on 32-bit, because the full range of an
unsigned int doesn't fit into a signed int, but my understanding is
that D is somewhat lax about signed/unsigned matters for the sake of
convenience.



More information about the Digitalmars-d mailing list