The following line (pure c) compiles cleanly on windows (win7 64 bits + codeblocks 13 + mingw32) and debian (wheezy 32 bits + codeblocks 10 + gcc) but raises warning on kali (64 bits + codeblocks + gcc). Any comments? I mean, why do I get this warning, though the same line compiles w/o any warning on windows & debian?
void* foo(void *dst, ...) {
// some code
unsigned int blkLen = sizeof(int); // this line ok.
unsigned int offset = (unsigned int) dst % blkLen; // warning here!
// some code cont...
}
The message in codeblocks is: "error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]"
note: my compiler options are -std=c99 -Werror -save-temps
(same on all three systems).
edit 2:
Though I've managed to have it compiled w/o warning using the preprocessor lines below,
@Keith Thompson (see below) has a crucial point about the issue. So, my last decision is using uintptr_t
would be a better choice.
edit 1: Thanks for everyone replied. As all the replies note, the problem is a 32 bits vs 64 bits issue. I've inserted following preprocessor lines:
#if __linux__ // or #if __GNUC__
#if __x86_64__ || __ppc64__
#define ENVIRONMENT64
#else
#define ENVIRONMENT32
#endif
#else
#if _WIN32
#define ENVIRONMENT32
#else
#define ENVIRONMENT64
#endif
#endif // __linux__
#ifdef ENVIRONMENT64
#define MAX_BLOCK_SIZE unsigned long long int
#else
#define MAX_BLOCK_SIZE unsigned long int
#endif // ENVIRONMENT64
and then replaced the problem line as:
unsigned int offset = (MAX_BLOCK_SIZE) dst % blkLen;
Now, everything seems OK.