64bitporting

Consider third-party API and upgrade/downgrade software issue

Replace (int) &x casts and typing with intptr_t and (unsigned int) &x with uintptr_t

void* foo (int key, void *value)
{
    return goo((const void*)(intptr_t) key); // replace goo((const void *)key);
}

be careful about signed comparison with unsigned variable which will always be rise to unsigned!!

    int a = -1;
    unsigned int b = 256;
    assert(a > b);

ptrdiff_t to stored pointer difference

indicate the variable size for printf format

%[parameter][flags][width][.precision][length]type
length
Character Description
hh For integer types, causes printf to expect an int sized integer argument which was promoted from a char.
h For integer types, causes printf to expect an int sized integer argument which was promoted from a short.
l For integer types, causes printf to expect a long sized integer argument.
ll For integer types, causes printf to expect a long long sized integer argument.
L For floating point types, causes printf to expect a long double argument.
z For integer types, causes printf to expect a size_t sized integer argument.
j For integer types, causes printf to expect a intmax_t sized integer argument.
t For integer types, causes printf to expect a ptrdiff_t sized integer argument.
printf format for int64_t
#include <inttypes.h>

uint64_t x;
uint32_t y;
intptr_t ptr;
printf("x: %"PRId64", y: %"PRId32", ptr: %"PRIdPTR"\n", x, y, ptr);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License