Compiler not detecting obviously uninitialized variable

前端 未结 4 1071
一整个雨季
一整个雨季 2020-12-01 11:50

All C compilers I\'ve tried won\'t detect uninitialized variables in the code snippet below. Yet the case is obvious here.

Don\'t bother about the functionality of t

4条回答
  •  鱼传尺愫
    2020-12-01 12:16

    Yes, it should raise a warning about that uninitialized variable, but it's a GCC bug. The example given there is:

    unsigned bmp_iter_set ();
    int something (void);
    
    void bitmap_print_value_set (void)
    {
        unsigned first;
    
        for (; bmp_iter_set (); )
        {
            if (!first)
                something ();
            first = 0;
        }
    }
    

    And diagnosed with -O2 -W -Wall.

    Unfortunately, this year is the 10 year anniversary of this bug!

提交回复
热议问题