variations of int sizes (and signded/unsigned) between platorms

Kirk McDonald kirklin.mcdonald at gmail.com
Tue Apr 24 00:36:23 PDT 2007


Jason House wrote:
> I have a small section of code that is giving me issues moving between 
> two machines.  On my amd64 machine, find returns a long and the slice 
> operation expects ulongs.  On my friend's machine, find returns an int 
> and refuses to accept cast(ulong)startComment.  Maybe it should be 
> cast(uint)startComment?  Of course, that won't work on my machine.
> 
> Rather that try to decipher this with version checks (when I don't know 
> how this varies from system to system), what's the proper way to solve 
> this?  I'm using gdc on my amd64 machine.  I'm not sure if my friend is 
> using gdc or dmd... or even if this is a variation form one version of 
> phobos to another.
> 

It seems like a version statement would be exactly the right thing to 
use in this case. Try something like this:

version (X86_64) {
     alias ulong find_t;
} else {
     alias uint find_t;
}

Then, in the slice, use a cast(find_t).

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list