digitalmars.D - windows64/linux64 Error: cannot implicitly convert expression of type
- Anastasios Tsiolakidis (10/10) Feb 18 2013 Hello,=0A=0Athis is perhaps something for d.learning, except that I don'...
- anonymous (10/17) Feb 18 2013 [...]
- Nick Sabalausky (16/37) Feb 18 2013 Line 72 should be:
- Steven Schveighoffer (10/23) Feb 18 2013 Make sure the linux compiler you are using is 64 bit.
Hello,=0A=0Athis is perhaps something for d.learning, except that I don't s= ee 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=0A=0A=0Ah3.d(72= ): Error: cannot implicitly convert expression (g0.length) of type ulong to= int=0A=0A=0AOn 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?=0AThanks=0A=0AAT=0A
Feb 18 2013
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;
Feb 18 2013
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 ATLine 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.
Feb 18 2013
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? ThanksMake 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
Feb 18 2013