This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: always_inline attribute


Thanks Thomas.

On Wed, Dec 23, 2009 at 7:09 PM, Thomas Martitz
<thomas.martitz@student.htw-berlin.de> wrote:
> Am 23.12.2009 14:35, schrieb kum:
>>
>> Hi,
>> I am using gcc v4.1.0 for mips (host:linux). With -O2 gcc does not
>> produce an inline function if the definition of the inline function is
>> in a different file than the caller. Am I missing something here?
>> Cannot I have inline function defined in different file?
>>
>> inline int __attribute__((always_inline)) foo()
>> {
>> // do something;
>> return 0;
>> }
>>
>>
>
>
> No, you can't. Compiler process each translation unit (=source file)
> separately, so it's not possible to insert code from another translation
> unit.
>
> In your example it will be only inlined in the file it's defined in.
> Additionally a function body is created because the function is not static.
>
> Put the inline in a header file, make it static and #include it from each
> source file you want to call it from.
> Best regards.
>



-- 
kum


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]