Jean-Luc Nacif Coelho Jean-Luc Nacif Coelho - 1 month ago 39
C Question

How to make compiler not show int to void pointer cast warnings

I have some code that does lots of casting from int to void* and vice-versa (i don't care if it's ugly. I like having generic stuff)

Example:

typedef struct _List {
long size;
long mSize; // Max size
void** elementArray;
}List;

List l;
...
int i = 2;
l.elementArray[i] = i; // Intentional usage of pointer as integer
// Actual size of pointer does not matter


but when i compile i get a bajillion

warning: cast to 'void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast]


warnings.
Is there a flag to tell gcc to not print this specific warning?

I'm compiling with -Wall, so I'm not sure if i can make this go away that easilly

Answer

apparently just take the flag that the compiler gives you and slap a "no" in front of it does the trick!

-Wno-int-to-void-pointer-cast