I need to find all such places in my source code where a pointer of any type is implicitly converted to void *
or a way to stop these implicit conversions.
For example:
int *
to void *
char *
to void *
Base *
to void *
Is there any gcc warning or error flag which detects all such lines where a pointer is implicitly converted to void *
?
Say you have a simple program like
#include <string.h>
int main()
{
char* apples = "apples and pears";
char fruit[1024];
void* avoid;
int aint;
float afloat;
avoid = &aint;
avoid = &afloat;
memcpy(fruit, apples, strlen(apples) + 1);
}
Here is a trick that will tell you where some of the implicit conversions are happening. Add this at the start of the program
#define void double
You will get a lot of compile errors: including where the implicit conversions are happening. It won't spot void* = double* so you'll need to try again with
#define void int
to spot the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With