Emulating GCC's __builtin_unreachable?

前端 未结 5 1862
春和景丽
春和景丽 2020-12-24 13:18

I get a whole lot of warnings about switches that only partially covers the range of an enumeration switched over. Therefor, I would like to have a \"default\" for

5条回答
  •  青春惊慌失措
    2020-12-24 13:37

    Hmm, something like (since __builtin_unreachable() appeared in 4.5):

    
    #define GCC_VERSION (__GNUC__ * 10000 \
                                   + __GNUC_MINOR__ * 100 \
                                   + __GNUC_PATCHLEVEL__)
    #if GCC_VERSION >= 40500
    #define my_unreachable()  __builtin_unreachable()
    #else
    #define my_unreachable() do { printf("Oh noes!!!111\n"); abort(); } while(0)
    #endif
    
    

提交回复
热议问题