www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Simple .d file passed in -m32 model, but failed in -m64 model. Why?

reply David Wang <osx.david live.com> writes:
Thank you Brad Roberts, at first I remove MinGW's PATHs in my system, and then
I successfully compiled the DMD, then I added back the MinGW's PATHs to the
system.  :-)


But, when I in Linux (Fedora 14 X86_64) system, I compiled a simple d file in
32bit model and 64 bit model I got different results.

Details:
1). test.d source:
=================
import std.stdio;



void main()

{

    writeln("Under 32bit model & 64bit model: \n");



    int[] months = new int[12];

    months = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99];



    writeln("Original months array value: \n", months,
"\n\n=====================");



    writeln("start to bind in turn:");

    foreach (i, ref e; months)

    {



        writeln("index i = ", i, ", \"looked \'in\' array\" value e = ", e);



        e = i + 1;



        writeln("temp i = ", i, ", temp e = i + 1 = ", e);

        writeln("months array: ", months);

        writeln("used i = ", i, ", and used e = ", e, "\n");



    }



    writeln("finished binding...");

    writeln("=====================\n\nFinal months array value: \n", months);




}
=================

2). I compile it using the command:
[David Ocean ~]$ dmd -m32 test.d
And I successfully got the result "test" file.

3). I compile it using the command:
[David Ocean ~]$ dmd -m64 test.d
And I got the error:
"test.d(18): Error: cannot implicitly convert expression (i + 1LU) of type
ulong to int"

Why the same source file shows different results?
How to fix this problem?

Waiting for kindly help.

Daivd.
Feb 20 2011
parent David Nadlinger <see klickverbot.at> writes:
On 2/20/11 3:25 PM, David Wang wrote:
 Why the same source file shows different results?

Because the array index »i« in your foreach loop is of type size_t, which is uint (32 bit wide) on x86_32 and ulong (64 bit wide) on x86_64. By the way, using D2, a shorter way to initialize the array would just be »auto months = array(iota(1,13))«. David
Feb 20 2011