Solved

Inline functions and LTO

Posted on 2010-09-08
5
771 Views
Last Modified: 2012-05-10
Hi *,

I'm a little confused with how to take full advantage of GCC's new LTO and some inline functions. I have read websites like http://www.linuxtopia.org/online_books/programming_tool_guides/linux_using_gnu_compiler_collection/inline.html however have to say i'm very confused.

I have a situation where I have one library.a and another library2.so and then some header and source files. Where do I put 'inline', 'extern inline' and 'static inline'? In just the headers, just the source or both? And in what situations!

I'm planning on using '-flto -fuse-linker-plugin -fwhole-program' and have compiled and installed GCC with '--enable-lto --enable-gold' so hopefully it will be able to link and inline/optimise all my code as if it were one (if I understand LTO that is).

Many thanks in advance,
James
0
Comment
Question by:James_h1023
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 33630434
inline functions are defined in each compilation unit where they are used.

If only one compilation unit uses the inline function, then you'd generally place the definition in the .c/.cpp file for that compilation unit.

If multiple compilation units use the inline function, and/or if you want to make it available as part of the library API, you'd place the definition in a header file, and include that header file in every compilation unit where it's used.
0
 
LVL 4

Author Comment

by:James_h1023
ID: 33634476
Thanks for a quick reply.

The first makes, sense. With the latter, would I also need to place the definition in the .c file as well as the header?

Also where should I use extern and static with regard to inline?

Many thanks,
James
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 500 total points
ID: 33635908
>> would I also need to place the definition in the .c file as well as the header?

No, since the definition is in the header file, and since you include the header file in the .c file, the .c file will have all it needs.


>> Also where should I use extern and static with regard to inline?

extern and static determine the linkage of the function (just like for a normal non-inline function) :

'extern inline' will cause object code to be generated for the function (with external linkage), so it can be called from outside the translation unit(s) where it's defined. It provides two ways of using the function : either inlined or as a normal (external) function call.

'static inline' ensures that if object code is generated for the function, then it will have static linkage. Every translation unit where the function is defined can have inlined versions of the function and/or a static normal function.
0
 
LVL 4

Author Comment

by:James_h1023
ID: 33636061
Ah ok I get it.

Many thanks for your help.
James
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 33636084
Glad to be of assistance :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now