[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Inline functions and LTO

Posted on 2010-09-08
Medium Priority
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,
Question by:James_h1023
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 53

Accepted Solution

Infinity08 earned 2000 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

649 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