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

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Apr 24 01:21:02 PDT 2007


Kirk McDonald wrote:
> 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).

Or you could just use ptrdiff_t...


More information about the Digitalmars-d-learn mailing list