How to suppress warnings for "void *" for "foo *" conversions (reduced from errors with -fpermissive)

I am trying to compile some c code with g ++ (yes, specifically). I get errors, for example (for example):

error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive] 

adding -fpermissive to my compilation options:

 error: invalid conversion from 'void*' to 'unsigned char*' [-Werror=permissive] 

which seems to be an error due to -Werror , however adding -Wno-error=permissive -Wno-permissive results in:

 error: -Werror=permissive: no option -Wpermissive error: unrecognized command line option "-Wno-permissive" [-Werror] 

How to disable warnings (globaly) for conversions from void * to other types of pointers?

+8
g ++ suppress-warnings
source share
2 answers

You cannot "turn off warnings for conversions from void* to other types of pointers" because this is not a warning - this is a syntax error.

What happens here is that you use -fpermissive , which lowers some errors, including this one, to warnings and, therefore, allows you to compile some incorrect code (obviously, many types of syntax errors, such as missing curly braces, cannot be reduced to warnings, because the compiler cannot know how to fix them in order to turn them into understandable code).

Then you also use -Werror , which updates all warnings to errors, including "warnings" in which -fpermissive included your error.

-Wno-error used only to negate -Werror , that is, -Werror treats all warnings as errors, except for the warnings specified in -Wno-error , which remain as warnings. As the -W flag suggests, both of these flags work with warnings, so they cannot do anything with this particular problem, because what you are here is a mistake. There is no β€œwarning” for such an invalid conversion that you can turn off and turn on with -Werror , because this is not a real warning β€” this is an error that -fpermissive simply calls it as a warning.

In this case, you can compile your inappropriate code using -fpermissive and not using -Werror . This will still give you a warning, but, like all warnings, it will not prevent a successful compilation. If you intentionally try to compile inappropriate code, then using -Werror does not make sense because you know that your code contains errors and therefore leads to warnings even with -fpermissive , so specifying -Werror equivalent to saying "Please do not compile my inappropriate code, although I just asked you. "

The further you can get g ++ for warning, it is to use -fsyntax-only , which will check for syntax errors and nothing else, but since you have a syntax error, this will not help you, and best of all you can do it, it turned into warning with -fpermissive .

+7
source share

How to disable warnings (globaly) for conversions from void * to other types of pointers?

Well, this may require direct interaction with the compiler code. This is probably not what you want. You want to fix your code. Firstly, these are not warnings, but errors . You need to drop void* because you cannot convert void* to anything without pronouncing it first (this is possible in C, but it is less safe than C ++).

For example, you will need to do

 void* buffer = operator new(100); unsigned char* etherhead = static_cast<unsigned char*>(buffer); ^ cast 

If you need a dynamically allocated buffer of 100 unsigned char , then you better do it

 unsigned char* p = new unsigned char[100]; 

and avoid casting.

void pointers

+1
source share

All Articles