Integral promotion and operator+=

后端 未结 2 1190
孤独总比滥情好
孤独总比滥情好 2021-01-18 04:14

I need to eliminate gcc -Wconversion warnings. For example

typedef unsigned short     uint16_t;

uint16_t a = 1;
uint16_t b = 2;
b += a;

gi

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 04:40

    I need to eliminate gcc -Wconversion warnings.

    You don't say why but this is actually unlikely.

    From the GCC wiki page on this switch:

    Why isn't Wconversion enabled by -Wall or at least by -Wextra?

    Implicit conversions are very common in C. This tied with the fact that there is no data-flow in front-ends (see next question) results in hard to avoid warnings for perfectly working and valid code. Wconversion is designed for a niche of uses (security audits, porting 32 bit code to 64 bit, etc.) where the programmer is willing to accept and workaround invalid warnings. Therefore, it shouldn't be enabled if it is not explicitly requested.

    If you don't want it, just turn it off.

    Mangling your code with unnecessary casts, making it harder to read and maintain, is the wrong solution.

    If your build engineers are insisting on this flag, ask them why, and ask them to stop.

提交回复
热议问题