Inline functions and LTO

Posted on 2010-09-08
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 however have to say i'm very confused.

I have a situation where I have one library.a and another 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,
Question by:James_h1023
  • 3
  • 2
LVL 53

Accepted Solution

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.

Author Comment

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,
LVL 53

Assisted Solution

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.

Author Comment

ID: 33636061
Ah ok I get it.

Many thanks for your help.
LVL 53

Expert Comment

ID: 33636084
Glad to be of assistance :)

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
a free alternative to cpanel? 1 58
Fixing Non-Standard characters in text 8 90
Virtualizing very old guest OS 4 79
wipe a usb using python 5 22
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

932 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

11 Experts available now in Live!

Get 1:1 Help Now