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

Re: Symbols and C++ inline constructor

On Sun, Jan 08, 2012 at 10:26:42AM +0100, Tobias Frost wrote:
> Just a general remark just came into my mind about the symbols
> dicssusion:
> Is is really *safe* to use inline methods as API in libraries?

Just trying to test this with the following code:

#include <string>

class test

  test(std::string const& var):


  std::string v;

static test t;
static test t2("foo");

Compiling, linking and testing with
g++ -fPIC -finline -c -o test.o test.cc
g++ -shared -o test.so test.o         
nm -C -D test.so

Oddly, the constructors are only used if I actually make use of them.
i.e. delete the "static test ..." at the end and compare.  If they
are used, I do see a non-inlined function appear though, albeit a
"W" (weak) symbol whether or not I explictly have the "inline"
keyword in the sources.  Possibly my example is too simple.  I'm
most surprised about the functions only being compiled on use even
without the inline.  Maybe I need to take them out of the class
definition and inline the separate functions.

So not all bad--if you use an inlined function you do appear to get
a symbol emitted.


  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Reply to: