www.digitalmars.com         C & C++   DMDScript  

D - dmd -O bug & conversion to short bug

The following code produces the wrong results when compiled with the -O
switch
for the routines not defined as extern(C). Those defined as extern(C) work
fine.This bug
was reported previously but was not fixed in the lastest version.

Also, the functions are supposed to return a short, but in some case they
return a 32bit number

int main()
{
    short s=HIWORD(0xFFFDDDD); //returns 0xFFFDDDD  & 32bit short when -O is
used !
    short t=LOWORD(0xFFFFCCCC); // always returns a 32bit short !
    short v=HIWORD_(0xFFFEEEE); // works with -O & returns a short


    printf("%x %x %x %x\n",s,t,v,x);
    return 0;
}

short HIWORD(uint i)
{
    return (short)(( i >> 16) & 0xFFFF);
}

short LOWORD(uint i)
{

    return (short)i;
}
extern (C) short HIWORD_(uint i)
{
    return (short)(( i >> 16) & 0xFFFF);
}
Jan 18 2004