[Top][All Lists]

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

Re: [avr-gcc-list] efficiency of assigning bits

From: David Brown
Subject: Re: [avr-gcc-list] efficiency of assigning bits
Date: Mon, 21 Mar 2005 08:26:07 +0100

> Jim Brain wrote:
> > My understanding was that C only
> > promotes to integer when doing negation
> > or when other operands are integer.
> This is the sort of thing you should probably go back and check on before
> posting here.
> > I've never seen constants promoted
> > to int in a normal (1<<X) mode.
> This has nothing to do with what the ANSI C specification requires.  This
> just indicates that the optimizer has determined that the result will be
> same whether the operands are processed as integers or at their declared
> size.  By the way, the expression you give as an example contains an
> of type integer (the literal constant 1), so even by your flawed
> understanding of C you should realize that C requires the promotion of X
> int in the abstract machine.  If you don't see this in the generated
> code, it is because the optimizer is at least half-way decent.

I don't know about you, but I consider the optimizer to be part of my tool
set, just like the compiler itself.  If the compiler is capable of
generating good object code from my preferred form of source code
expression, then I don't care whether ANSI says it is "sort of cheating but
all right in this case".  Are we supposed to care about what code is
generated using an inferior compiler, or on a different architecture, when
talking about low-level hardware access on a specific microcontroller?
There are times when C's integer promotion is a PITA, but for simple bit
manipulation, all the compilers I have used on 8-bit architectures have been
smart enough to generate sensible code.  Unnecessarily sprinkling the code
with (unsigned char) casts does nothing for the code efficiency, or code
portability, and detracts from code readability - so don't do it.

> > And, when I negate, I do:
> > PORT &=(unsigned char)~ADDR_CLK;
> > to cancel the promotion.
> You can't "cancel" promotions.  All you can do it take the result of an
> operand or expression evaluation and cast (perform an explicit conversion)
> to some type.  This is what you are doing here.
> Graham.
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

reply via email to

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