3 ms·
GCC's -Wconversion has some issues. For example, good luck getting gcc to /not/ emit a warning for this code, in C or C++. I have yet to find the appropriate ca
by usefulcat 5y ago
GCC's -Wconversion has some issues. For example, good luck getting gcc to /not/ emit a warning for this code, in C or C++. I have yet to find the appropriate cast to avoid a warning. Clang does not warn for this.
typedef struct {
unsigned value : 4;
} S;
void foo(S* s, unsigned value) {
// error: conversion from 'unsigned int' to 'unsigned char:4' may change value
s->value = value;
}
I mean, I guess I can see the rationale.. it's just annoying to have to resort to using pragmas to turn off -Wconversion whenever I need to assign to a bitfield.
- Denvercoder9 5y agoDoes it still warn if you do `s->value = value & 0x0F`? That seems like a reasonable alternative to pragmas if it works.