[C] Trying to solve type conversion warning

I can't seem to correct a warning i get with -Wconversion (gcc)

Some minimal code that displays it :
1
2
	unsigned char mask2=0;
	mask2 = (~mask2);

The warning says Conversion to 'unsigned char' from 'int' may alter it's value at the second line
If i understand it correctly, this means that the ~ operator always gives an int if the type is smaller and/or of different 'signedness'?
Cast?
1
2
unsigned char mask2=0;
mask2 = static_cast<unsigned char>(~mask2);
Last edited on
That's what i'll do if i have to, but i'd have liked a soluton without cast
Topic archived. No new replies allowed.