On inlining of functions across 2 or more object files

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

 



Hi all,

I have written a small app. Which needs some inline functions. I have
kept the inline functions in a separate file so that they are reusable
in the future. The core code resides in, say file1.cpp and the inline
function definitions reside in file2.cpp. (yes I am using c++). I am
compiling this like

$g++ -c file1.cpp
$g++ -c file2.cpp
$g++ -shared file1.o file2.o -o final.so

My question is that the functions which are called from file1.o are
inlined for speed. And they reside in file2.o. Now, the gcc docs say
inline functions are as fast as a macro. My question is, does the
inliine expansion work even when code is distributed across different
object files?

1) My (naive) view tells me, no it is not possible. At the third
stage, you are just linking. Code expansion happens at the compiling
and assembling stage. Is this correct?

2) I am assuming, whatever the actual behavior is, it is same for both
c and c++ compilers. I am pretty sure this _is_ correct. But a
confirmation i welcome.

Under any circumstances, it would be unacceptable for me to have an
inline function silently expanded to a "true" function.

I would be grateful if I can get feedback/clarification on my doubts.
Further, this small ambiguity should be preferably cleared up in the
web based docs itself. If maintainers allow,  I would like to
contribute this.

Thanks in advance,

-- 
Rohit Garg

http://rpg-314.blogspot.com/

Senior Undergraduate
Department of Physics
Indian Institute of Technology
Bombay

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux