Selectively remove warning message GCC

前端 未结 4 1710
走了就别回头了
走了就别回头了 2020-11-30 04:45

This piece of code:

Int32 status;
printf(\"status : %x\", status)

gives me the following warning:

jpegthread.c:157: warning         


        
4条回答
  •  春和景丽
    2020-11-30 04:59

    I presume you are looking for the

    #ifdef WIN32
    #pragma warning (disable: #num of the warning) 
    #endif
    

    Equivalent in GCC....

    You can search for options such as -Wno-conversion -Wno-format-security that do the job here

    http://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Warning-Options.html

    But in terms of the #pragma directive:

    I Quote from the GCC mailing list from Google:

    GCC does not, currently, provide the #pragma facility you are looking for.

    Do not lose hope! There are viable alternatives.

    The first best way to fix the code so it no longer emits the warning. Alas, you've stated you cannot do this. :-(

    NOTE: Have warnings turned up as verbose as your team can tolerate! [see below]

    The next best way to ignore the undesired warning is to post-process the output of GCC to a script (such as a Perl script) that strips out the specific, exact warning you want to ignore.

    The next way to ignore the undesired warning is to disable the warning for that translation unit. -Wno-foozle-mcgoogle, just for that particular translation unit. That's a mighty big hammer, though. And if the warning is in a header file, it may be pervasive throughout your entire project -- to which I'd direct you to the post-processing script solution (assuming you are disallowed from fixing the code).

    So currently no, there is no #pragma directive to disable specific warnings. Rather than using -Wall you could turn on as many warnings as you can minus specific ones.

    http://www.network-theory.co.uk/docs/gccintro/gccintro_31.html

    or fix the code

提交回复
热议问题