[Top][All Lists]

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

RE: [avr-gcc-list] refactoring to reduce code size

From: Sander Pool
Subject: RE: [avr-gcc-list] refactoring to reduce code size
Date: Wed, 29 Jan 2003 00:08:02 -0800

> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Behalf Of Yann Ramin

> Are you using #defines which calculate stuff? Try pre-calculating any
> variables (i.e., don't calculate values for the baud rate register, even
> in a #define, since it will turn into code. Use constants).

That is bad advise. Gcc, like all other c compilers will evaluate constant
expressions to a single constant in the assembly. So using #defines to
determine baud rate is a -good- idea as it makes code more readable and
easier to maintain at no cost:

#define F_CPU            16000000      /* 16Mhz */
#define UART_BAUD_RATE      9600      /* 9600 baud */


        UBRR1L = (u08) UART_BAUD_SELECT;

This carries no code size penalty over hard coding a numeric constant.

So maybe you meant "don't calculate constants at run-time"?


avr-gcc-list at http://avr1.org

reply via email to

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