Easy way find uninitialized member variables

后端 未结 11 962
时光说笑
时光说笑 2020-11-29 22:20

I am looking for an easy way to find uninitialized class member variables.

Finding them in either runtime or compile time is OK.

Currently

11条回答
  •  忘掉有多难
    2020-11-29 22:53

    Consider the following code

    unint.cpp:

    int main()
    {
        int a;
        int b;
        a++;
        b = b + 5;
    
        return 0;
    }
    

    If the code is compiled with following comment, the warning messages shall be displayed.

    g++ -O3 -Wuninitialized unint.cpp

    Note: the -Wuninitialized needs the -O3 option also.

提交回复
热议问题