[Top][All Lists]

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

Re: [avr-gcc-list] inline vs. #define

From: Hudaidai
Subject: Re: [avr-gcc-list] inline vs. #define
Date: Wed, 26 Mar 2003 13:11:6 +0800

>How are inline functions handled by avr-gcc?
>if i use 
>#define i2c_wait() while (!(TWCR & _BV(TWINT)))
>avr-size says: 
>text      data     bss     dec     hex filename
>388          0       1     389     185 i2c.elf
>instead if i use 
>inline void i2c_wait(void) 
>       while (!(TWCR & _BV(TWINT)));
>avr-size output looks like
>text      data     bss     dec     hex filename
>398          0       1     399     18f i2c.elf
>Why is there a difference in size?
>Any help would be appreciated.
>avr-gcc-list mailing list

According to the GCC manual:

"When a function is both inline and static, if all calls to the function are 
integrated into the caller, and the function's address is never used, then the 
function's own assembler code is never referenced. In this case, GCC does not 
actually output assembler code for the function, unless you specify the option 
-fkeep-inline-functions. Some calls cannot be integrated for various reasons 
(in particular, calls that precede the function's definition cannot be 
integrated, and neither can recursive calls within the definition). If there is 
a nonintegrated call, then the function is compiled to assembler code as usual. 
The function must also be compiled as usual if the program refers to its 
address, because that can't be inlined. 

"When an inline function is not static, then the compiler must assume that 
there may be calls from other source files; since a global symbol can be 
defined only once in any program, the function must not be defined in the other 
source files, so the calls therein cannot be integrated. Therefore, a 
non-static inline function is always compiled on its own in the usual fashion. "

In fact, GCC will automaticlly make most static functions inline when -O3 
option is used.

Daidai Hu 

reply via email to

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