Ignoring return values in C

前端 未结 10 1447
轻奢々
轻奢々 2020-12-08 13:39

Lately, I started using lint for static code analysis. One of the warning I get sometimes is regarding this issue. Let\'s say for instance that I\'ve got the following funct

10条回答
  •  悲&欢浪女
    2020-12-08 14:00

    One way to do this with Clang and GCC compilers is with a pragma:

        /* ... */
    
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-result" 
    
        foo(); /* this specific unused-result warning gets ignored during compilation */
    
    #pragma GCC diagnostic pop 
    
        /* ... */
    

    The push-pop combination wraps the ignored directive so that warnings can be triggered elsewhere in your code. It should be easier for anyone reading your source code down the road to see what this code block does.

提交回复
热议问题