problem with detzcode on machines w/64 bit longs

Chris G Demetriou Chris_G_Demetriou at LAGAVULIN.PDL.CS.CMU.EDU
Fri Mar 10 14:17:23 UTC 1995


[ for once i wish for a unidiff...  8-]

> How about this simple change?
> 
> [ OLD ]
>
> ! 	result = 0;
>   	for (i = 0; i < 4; ++i)
>   		result = (result << 8) | (codep[i] & 0xff);
>   	return result;
>
> [ NEW ]
>   
> ! 	result = ~0;
>   	for (i = 0; i < 4; ++i)
>   		result = (result << 8) | (codep[i] & 0xff);
>   	return result;

right, but then you _always_ have the top 32 bits set.  the point is
to get the effect of sign extension on the MSB.

You could also do something like:

	result = (int)result;

right before you return the result.  however, _that_ depends on the
assumption that "int" is 32 bits, which definitely isn't true on all
of the machines out there (unless i'm mistaken, it's not true on
macintoshes with certain C compilers, and on crays)...



cgd




More information about the tz mailing list