This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ 'extern inline' magic possible?


In a C++ application consisting of a large number of source files, I've got a situation where there is a non-member function that *some* users could inline (because they can see the definition of the classes involved in the function's parameters and return value) and other users cannot inline (because they are only know of those classes due to forward declarations, and the function accepts and returns pointers to objects).

As it stands right now, the header file declares this function for all callers, and there is one source file that provides the definition; this works, because all callers call the function after the library that provides the function is dynamically linked into their process.

The function, though, is terribly simple, and the function call overhead easily dwarfs the code the function actually runs (in one case, the function is nothing more than a wrapper for the equivalent of a static_cast<>). If the compiler could see the function body it would be able to inline it in a large number of cases, reducing code size and improving performance.

I have three source files involved here:

aF.h contains only a forward declaration of class Foo, and a declaration of 'void bar(const Foo *)'.

a.h contains the declaration and definition of class Foo, and a declaration of 'void bar(const Foo *)'.

a.cpp contains the definition of 'void bar(const Foo *)'.

I would like to come up with some construction like the 'extern inline' that GCC supports for C mode, so that a.h could contain the declaration *and* definition of 'bar', allowing code that includes a.h to have 'bar' be inlined if the compiler chooses to do so (and leave an external reference to 'bar' if necessary so that the version built from a.cpp will be used). So far my attempts have only resulted in various re-definition or re-declaration errors.

Is there a way to do this in C++ mode? I see lots of pages with useful details and example for C mode, but not for C++ mode. I am *not* specifying '-std' to the compiler at all, and am using GCC 4.4; I've tried using '-std=c99' but that doesn't seem to do what I want (with the definition in the header marked 'inline' and the definition in the source file marked 'extern inline').

--
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kfleming@digium.com
Check us out at www.digium.com & www.asterisk.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]