warning: return makes pointer from integer without a cast but returns integer as desired

It’s not obvious what you’re trying to accomplish here, but I’ll assume you’re trying to do some pointer arithmetic with x, and would like x to be an integer for this arithmetic but a void pointer on return. Without getting into why this does or doesn’t make sense, you can eliminate the warning by explicitly casting x to a void pointer.

void *myfunction() {
 int x = 5;
 return (void *)x;
}

This will most likely raise another warning, depending on how your system implements pointers. You may need to use a long instead of an int.

void *myfunction() {
 long x = 5;
 return (void *)x;
}

Leave a Comment