Consider the following code:
#include<stdio.h>
#define msizeof(type) ((char*)(&type) - (char*)(&type - 1))
int main()
{
int x;
printf("%u %u\n", msizeof(x), sizeof(x));
return 0;
}
The Above code when compiled with g++ compiles just fine and works well without any wanrings, while in gcc it gives the following warning: integer overflow in expression
. Though the code works fine on running. This warning goes away when I change the macro to: #define msizeof(type) ((char*)(&type + 1) - (char*)(&type))
.
My Questions:
1. What does the warning integer overflow in expression
mean?
2. Why am I getting it?
3. Why does changing it to #define msizeof(type) ((char*)(&type + 1) - (char*)(&type))
remove the warning?
4. Why the warning doesn't occur in C++?
Thanks in Advance.