Re: Help me understand this compiler warning.



pete (in 44DF1184.CAE@xxxxxxxxxxxxxx) said:

| The left operand is uc[7], which is of type unsigned char.
|
| Your posted code doesn't do anything to prevent
| type unsigned char from being promoted to type int.
|
| Why do you think that in
| (uc[7] >> 4)
| that the left operand won't be promoted to int?
|
| "If an int can represent all values of the original type, the
| value is converted to an int; otherwise, it is converted to
| an unsigned int. These are called the integer
| promotions."

You're absolutely right. I'm not sure how I managed it; but I looked
it up, read it carefully, and concluded that the unsigned char would
be promoted to an unsigned int - very wrong.

Thanks for getting me on track - and to the OP, my apologies for an
incorrect response.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto


.



Relevant Pages

  • Re: Help me understand this compiler warning.
    ... ANDing an unsigned char with an ... int /could/ produce a signed int - which, according to 6.5.7, could ... 6.3.1.8- rules for integer promotions - adds a bit of ... which is of type unsigned char. ...
    (comp.lang.c)
  • Re: complement of an unsigned char
    ... Isn't an unsigned char 8 bits long? ... only if the corresponding bit in the converted operand is not set). ... So c is promoted to int (unless CHAR_MAX> INT_MAX, ... promotions are done. ...
    (comp.lang.c.moderated)
  • Re: va_args Conformance
    ... static void test{ ... The second argument of his call to testhas a type of int. ... va_argwith a type of one_char, which is a typedef for unsigned char. ... promoted according to the default argument promotions), ...
    (comp.lang.c)
  • Re: va_args Conformance
    ... static void test{ ... unsigned char * byte; ... The second argument of his call to testhas a type of int. ... promoted according to the default argument promotions), ...
    (comp.lang.c)
  • Re: Why is this cast nessasary
    ... I don't know what you mean by "The Compiler is 8 Bits". ... bit com_putchar (unsigned char c) ... any subexpression of type unsigned char is going to ... be promoted to either int or unsigned int. ...
    (comp.lang.c)