Why do I get “warning: missing initializer for member”? [-Wmissing-field-initializers]

后端 未结 5 2108
名媛妹妹
名媛妹妹 2021-01-04 20:14

I\'m wondering why I am getting a warning about initialization in one case, but not the other. The code is in a C++ source file, and using GCC 4.7 with -std=c++11

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 21:01

    The compiler warns that all members are not initialized when you initialize the struct. There is nothing to warn about declaring an uninitialized struct. You should get the same warnings when you (partially) initialize the uninitialized structs.

    struct sigaction old_handler, new_handler;
    old_handler = {};
    new_handler = {};
    

    So, that's the difference. Your code that doesn't produce the warning is not an initialization at all. Why gcc warns about zero initialized struct at all is beyond me.

提交回复
热议问题