Using typecasting to remove gcc compiler warnings
问题 I am doing embedded ARM programming with gcc 4.9. I've been using the -Wconversion switch because it's in my company's default dev tool configuration. I'm using the stdint.h types (uint8_t, uint32_t, etc). The compiler creates warnings every time I perform a compound assignment or even simple addition. For example: uint8_t u8 = 0; uint16_t u16; // These cause warnings: u8 += 2; u8 = u16 >> 8; The "common method" to fix this is to use casts, as discussed here and here: u8 = (uint8_t)(u8 + 2);