Ignoring return values in C

前端 未结 10 1444
轻奢々
轻奢々 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:16

    For a static code checker to be useful, it should report also the ignored return values, which can lead very often to difficult to track errors - or missing error handling.

    So you should keep the (void) or deactivate the check for printf. Now you have several options for doing it in a readable manner. I use to wrap the function inside a new function like for example

    void printf_unchecked(const char* format, ...)
    

    where the not so nice cast takes place. Perhaps it's more practical to do it using a preprocessor macro in this case because of the varargs...

提交回复
热议问题