C++ 'extern inline' magic possible?

Jonathan Wakely jwakely.gcc@gmail.com
Tue Mar 1 21:52:00 GMT 2011


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 ...

// aF.h

class Foo;
void bar_ext(const Foo*);
#ifndef BAR_INLINED
#define BAR bar_ext
#endif

// a.h

class Foo { };
void bar_inl(const Foo*) { }
#undef BAR
#define BAR bar_inl
#define BAR_INLINED

this way you call BAR() and get the inline bar_inl if its definition
has been seen, or bar_ext otherwise.

But macros introduce their own problems so use with caution.



More information about the Gcc-help mailing list