What is a good programming pattern for handling return values from stdio file writing functions

前端 未结 13 1197
梦如初夏
梦如初夏 2021-01-02 11:28

I\'m working on some code that generates a lot of

ignoring return value of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’, declared with attribute warn         


        
13条回答
  •  执笔经年
    2021-01-02 12:08

    Your first solution looks ok. Usually a goto err; comes in more handy as you may need some common cleanup part (such as rewinding to a known position).

    To make GCC quiet just do:

    (void)fwrite (&blah, sizeof (blah), 1, fp);
    (void)fwrite (&foo, sizeof (foo), 1, fp);
    

提交回复
热议问题