问题
I have turned on -Wall
in my code to get rid of all warnings. Some however I want to allow within the code, so I disable those ones in code. Of the common ones, I can easily find out the warning number in Google and disable them like e.g.:
#pragma warning( disable : 4127 )
But of some, I can't possibly find the corresponding number. For example, I want to disable a:
warning : array subscript is of type 'char' [-Wchar-subscripts]
How do I find its number? Is there a searchable list? The Microsoft documentation isn't searchable on keyword, only on number.
回答1:
You are not using a Microsoft compiler, or at least not a Microsoft compiler front end. The warning is printed by the Clang front end. (GCC has a very similar warning, also called -Wchar-subscripts
, but the wording of the message is slightly different.)
Clang and GCC do not use numbers for warnings, but names. You can use these pragmata to disable the diagnostic:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wchar-subscripts"
The code which should be compiled without the warning follows, and with this, you can restore the previous state of the warning (typically enabled):
#pragma GCC diagnostic pop
Note that it says “GCC
” because the pragma actually works with GCC and Clang.
来源:https://stackoverflow.com/questions/47417179/how-to-find-out-the-number-of-a-c-warning