[Kde-bindings] Fwd: Qyoto/Kimono: A 64 bit unsafe function, build trouble on Debian unstable
Richard Dale
rdale at foton.es
Mon May 28 10:41:14 UTC 2007
On Sunday 27 May 2007, Arno Rehn wrote:
> qint64 key = (qint64) o->ptr;
> return (int) ((key >> (8 * sizeof(int) - 1)) ^ key);
Well I tried a quick experiment, and I'm not sure the result has the same
bytes as the original 'o->ptr' when there are 32 bits to a pointer and for
ints:
#include <stdio.h>
int main(int argc, char * argv[]) {
int before_calc = 0xAABBCCDD;
long long key = (long long) before_calc;
int after_calc = (int) ((key >> (8 * sizeof(int) - 1)) ^ key);
printf("before calc: 0x%8.8x after_calc: 0x%8.8x\n", before_calc,
after_calc);
printf("key: 0x%16.16x\n", key);
return 0;
}
gives:
before calc: 0xaabbccdd after_calc: 0x55443322
key: 0x00000000aabbccdd
But there may be something wrong with the test.
I think we should just '&' with 0xFFFFFFF to get the bottom 32 bits when
pointers are 32 bits, and use the above calc when they are 64 bits:
if (sizeof(void*) > sizeof(int)) {
qint64 key = (qint64) o->ptr;
return (int) ((key >> (8 * sizeof(int) - 1)) ^ key);
} else {
return (int) (o->ptr & 0xFFFFFFFF);
}
Does this code compile on a 64 bit machine though?
-- Richard
More information about the Kde-bindings
mailing list