When compiling C for a platform where int and long are both 32 bits, and long long is 64 bit (like clang or gcc -m32
or clang's wasm32-unknown-wasi target), I get errors about incompatible pointer types:
int32_t *i1 = NULL;
long *l1 = i1;
int64_t *i2 = NULL;
long *l2 = i2;
sizeof.c:13:11: warning: incompatible pointer types initializing 'long *' with an expression of type 'int32_t *' (aka 'int *') [-Wincompatible-pointer-types]
long *l1 = i1;
^ ~~
sizeof.c:15:11: warning: incompatible pointer types initializing 'long *' with an expression of type 'int64_t *' (aka 'long long *') [-Wincompatible-pointer-types]
long *l2 = i2;
^ ~~
2 warnings generated.
I find it strange, that neither int32_t
nor int64_t
is compatible with long
.
Why is there a warning if int and long are the same?