avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Re: Why is gcc promoting on an unsigned char?


From: David Gay
Subject: Re: [avr-gcc-list] Re: Why is gcc promoting on an unsigned char?
Date: Tue, 23 Dec 2003 10:12:01 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20030927

J.C. Wren wrote:
I rewrote the ?: slightly differently, so it's treated more like if/else. It produces the same code as the if() version. The second version (or more correctly, original version) of ?: is not optimizing correctly, based on my interpetation of the grammar. Considering that every thing is cast, I am unclear as to why it thinks it needs to promote to ints for the intermediate results.

Because the C standard says it must. To quote from section 6.5.15, conditional operator:
       If  both the second and third operands have arithmetic
       type, the type that the usual arithmetic  conversions  would
       yield  if  applied  to those two operands is the type of the
       result.  If both the operands have structure or union  type,
       the  result has that type.  If both operands have void type,
       the result has void type.

Where the usual arithmetic conversions include the rule that anything smaller than int is promoted to int.

David Gay
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]