www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug: cast to int is required on something that shouldn't.

There, found a big cockroach :) :

[code]
import std.c.stdio;

public static void main(char[][] args)
{
static int[] vector=[0xAABBCCDD, 0xDDCCBBAA, 0x11223344, 0x55667788];
for(int i=0; i<vector.length; i++) printf("vector[%d]: %d\n",i, vector[i]);
}
[/code]

test.d(5) cannot implicitly convert expression 2864434397 of type uint to int.
test.d(5) cannot implicitly convert expression 3721182122 of type uint to int.

(It should be assumed that the first two numbers are negative!...). 
This solves the problem, but I don't see the point of why a cast to int is
required:

[code]
import std.c.stdio;

public static void main(char[][] args)
{
static int[] vector=[cast(int) 0xAABBCCDD, cast (int) 0xDDCCBBAA, 0x11223344,
0x55667788];
for(int i=0; i<vector.length; i++) printf("vector[%d]: %d\n",i, vector[i]);
}
[/code]

Another bug that hasn't been corrected in D (it's there for quite a while!) is
the initialization issue:

[code]
import std.c.stdio;

public static void main(char[][] args)
{
int[] vector=[0x12345678, 0x38FF00CC, 0x11223344, 0x55667788];
for(int i=0; i<vector.length; i++) printf("vector[%d]: %d\n", i, vector[i]);
}
[/code]

test.d(5) variable vector is not a static and cannot have static initializer
Aug 23 2004