C not operator why do I get a warning -


whats wrong code

typedef unsigned char datum; /* set data bus width 8 bits. */      datum pattern;     datum antipattern;      antipattern = ~pattern;   remark[pa091]: operator operates on value promoted int (with possibly unexpected result) c:\filepath...\file.c 386  

compiler iar ewarm why should 2 char variables need converted int. why should complain change of sign when declared unsigned.

any idea cast use rid of warning?

the rules of c require unsigned char operands converted int (except in perverse c implementations).

once operand int, signed, , ~ operator may give unexpected results, because semantics signed integers , bit representations not specified c. compiler helpfully warning this.

you should use antipattern = ~ (unsigned int) pattern;. unsigned int, guaranteed value represented simple binary.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -