Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 19, 2013 windows64/linux64 Error: cannot implicitly convert expression of type ulong to int | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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 |
February 19, 2013 Re: windows64/linux64 Error: cannot implicitly convert expression of type ulong to int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anastasios Tsiolakidis | On Tuesday, 19 February 2013 at 03:33:48 UTC, Anastasios Tsiolakidis wrote: > 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. [...] > What's going on? Line 72: int n = g0.length; Apparently, you're compiling to 32bit on Windows, and to 64bit on Ubuntu. g0.length is of type size_t which is as large as your target bitness. int is always 32 bits large. Since you can't cram 64 bits into 32 bits, the compiler complains when targeting 64bit. Change that line to this: size_t n = g0.length; |
February 19, 2013 Re: windows64/linux64 Error: cannot implicitly convert expression of type ulong to int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anastasios Tsiolakidis | On Tue, 19 Feb 2013 03:13:14 +0000 (GMT)
Anastasios Tsiolakidis <abstractius@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.
|
February 19, 2013 Re: windows64/linux64 Error: cannot implicitly convert expression of type ulong to int | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anastasios Tsiolakidis | On Mon, 18 Feb 2013 22:13:14 -0500, Anastasios Tsiolakidis <abstractius@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
Make sure the linux compiler you are using is 64 bit.
Just because you are on a 64 bit system doesn't mean you are compiling 64-bit programs. For example, in the latest dmd, there is a linux/bin32 and linux/bin64 directory. *BOTH* will run on 64-bit linux, but only the 64 bit compiler will compile 64-bit programs.
That being said, as others have pointed out, the code really should use size_t and not int/uint.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation