Friday, July 17, 2009

» Educating upstream: C pointers are not int

Once and for all, a pointer (in C) is NOT an int It just happens to be one on 32bit systems, but the only proper type for casting a pointer into a number (for whatever reason, such as pointer arithmetics) is

To have that type, also add an #include on stdint.h where appropriate. It is really annoying when, as a packager, you keep running into C sources that have only been compiled and tested on 32bit systems and where the authors have assumed that they can cast their pointers to int. On x86_64, that generates quite a lot of warnings, on purpose: on 64bit systems, a pointer is an unsigned long. But don't rely on that either, just use intptr_t Arguably, it has been added in C99, and only as optional but hey, if you're in for a big heap of assumptions by doing pointer arithmetics, you could as well assume it's a modern C compiler and libc.

Labels: ,

0 Comments:

Post a Comment

<< Home