C++ 'extern inline' magic possible?
Kevin P. Fleming
kpfleming@digium.com
Wed Mar 2 13:00:00 GMT 2011
On 03/01/2011 04:52 PM, Jonathan Wakely wrote:
> On 1 March 2011 12:14, Kevin P. Fleming wrote:
>>
>> Yes, that was what my original post requested, but I now understand that any
>> solution that offered that would be non-compliant with the C++ standard. I
>> believe this code base is only using this technique to shave some compile
>> time for TUs that don't actually need the class definitions (they only
>> receive and send around pointers to the classes), but it's a cause of lower
>> performance and so I'll have to figure out whether removing the 'forward
>> declaration only' mechanism will be worth the effort.
>
> There is another option, which I'm loathe to mention ...
<snip macro example which makes everyone shudder <G>>
Yes, I considered that. I did arrive at a potential solution, although I
can't use it in this particular code base because of other
complications, but...
== test.h ==
class Foo;
void opaqueBar(Foo*);
template <typename T>
void Bar(T* obj)
{
opaqueBar(obj);
}
== test1.h ==
#include "test.h"
static void test1(Foo* obj)
{
Bar(obj);
}
== test2.h ==
#include "test.h"
class Foo
{
public:
void realBar();
};
template <>
inline void Bar<Foo>(Foo* obj)
{
obj->realBar();
}
static void test2(Foo* obj)
{
Bar(obj);
}
I think this still might be an ODR violation though, since there will
end up being two definitions of Bar() for Foo.
--
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
More information about the Gcc-help
mailing list