Earlier, I asked a similar question, but I’ve since changed my code. Now the compiler gives me a different warning. This is an example of what my code looks like now:
void *a = NULL;
void *b = //something;
a = *(int *)((char *)b + 4);
When I try to compile, I get “warning: assignment makes pointer from integer without a cast.” What does this mean, and what should I do to fix it?
To clarify, I don’t want ‘a’ to point to an address that is 4 bytes greater than ‘b’ (i.e., a != b+4). In my program, I know that the value stored at ((char *)b + 4) is itself another pointer, and I want to store this pointer in ‘a’.
Since, “the value stored at
((char *)b + 4)is itself another pointer”, simply add an explicit cast to the result:Since you’re assuming that
sizeof(void*)==sizeof(int), the code is not portable, but I am sure you already knew that.A portable alternative is to use
intptr_tinstead ofint.