This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C++ 'extern inline' magic possible?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: "Kevin P. Fleming" <kpfleming at digium dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 1 Mar 2011 01:10:16 +0000
- Subject: Re: C++ 'extern inline' magic possible?
- References: <4D6C35D1.4080104@digium.com> <mcrbp1velg1.fsf@google.com>
On 1 March 2011 00:25, Ian Lance Taylor wrote:
> "Kevin P. Fleming" <kpfleming@digium.com> writes:
>
>> 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.
>
> There is no equivalent to GNU C's "extern inline" in C++. ?By the way,
> "extern inline" is now actually known as __attribute__ ((gnu_inline)),
> as C99 defines "extern inline" to mean something different.
>
> In C++ you can simply define the function inline in a.h, and not define
> it at all in a.cpp. ?The right thing will happen.
That will work in practice, but it's technically an ODR violation.