variations of int sizes (and signded/unsigned) between platorms
Daniel Keep
daniel.keep.lists at gmail.com
Mon Apr 23 22:35:18 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.
>
>> $ dsss build
>> housebot.d => housebot-0.6
>> + /bin/rebuild -Idsss_imports/ -I. -S./ -I/include/d -S/lib/
>> -oqdsss_objs -Dddoc -unittest -w -g housebot.d -ofhousebot-0.6
>> warning - gtp.d:105: Error: implicit conversion of expression
>> (startComment) of type long to ulong can cause loss of data
>> Command /bin/rebuild returned with code 256, aborting.
>>
>> $ head -n 108 gtp.d | tail
>>
>> private void getArgs(out char[][] args){
>> char[] line = inStream.readLine();
>> auto startComment = find(line, "#");
>> char[] commentFree = line;
>> if (startComment > -1)
>> commentFree = line[0..startComment];
>> // Remove starting whitespace, trailing whitespace
>> // Also replace sequences of spaces and tabs with a
>> single space
>> char[] squeezedLine = strip(squeeze(tr(line, "\t","
>> ")," "));
find should probably be returning ptrdiff_t, since that looks like what
you're getting. If you try casting startComment to size_t on line 105,
that should work.
FYI:
| 32-bit alias | 64-bit alias |
size_t | uint | ulong |
ptrdiff_t | int | long |
Hope that helps.
-- Daniel
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list