how to ignore certain warings



  • hi

    im currently working with eclipse and gcc.
    there are external sources im using that produce warings.
    what i dont wanna do is to disable warnings in general, so i can see when something is suspicious.

    i would like to add a compiler instruction to the line in code that is causing the warning, just to say: "this one is OK, do not warn me about this"

    do you have any ideas?

    screenshots:
    https://imgur.com/a/NgLI1



  • GCC-specific (probably also supported by Clang): https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
    MSVC-specific: https://msdn.microsoft.com/en-us/library/aa273936(v=vs.60).aspx

    If there are a lot of those cases, it might still be better to ignore specific warnings for the whole file, as it will definitely hurt code readability if the source is littered with those pragmas.
    This will probably the case with the UNUSED macro, since it causes the warning for every line where it is used rather than for the single line where the macro is defined.

    I'm not sure whether it's possible to somehow integrate the pragmas into the macro itself, so that the preprocessor emits them along with the macro text that causes the warning in a
    way that the compiler can pick them up. Maybe someone with more expertise in preprocessor-magic knows a solution.

    An alternative for just the UNUSED macro might be to use GCC's __attribute__((unused)) instead, which will not cause this warning.

    Edit: The GCC doc (1st link) uses the _Pragma keyword in an example at the bottom of the page and MSVC also seems to support something similar via __pragma .
    With those it's definitely possible to integrate pragmas into a macro, if you're willing to go that far. Personally, i'd just disable the warning for the whole file if it's
    an external header or source file - having to maintain "patches" for external libraries increases overall maintenance costs: I try to avoid that wherever possible.


  • Mod

    I'm not sure whether it's possible to somehow integrate the pragmas into the macro itself, so that the preprocessor emits them along with the macro text that causes the warning in a
    way that the compiler can pick them up. Maybe someone with more expertise in preprocessor-magic knows a solution.

    The _Pragma operator has been standardised. (I'm confused as to why VC++ expects a different keyword.) However, I agree that if some external library code is diagnosed, one is better off simply ignoring that in the long run. This can be adjusted in the IDE, I'm sure. You should be careful not to overlook #warning directives, though :p


Anmelden zum Antworten