Re: C++ 'extern inline' magic possible?

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

 



Jonathan Wakely <jwakely.gcc@xxxxxxxxx> writes:

> On 1 March 2011 00:25, Ian Lance Taylor  wrote:
>> "Kevin P. Fleming" <kpfleming@xxxxxxxxxx> 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.

No, it's not (there may be a misunderstanding somewhere).  I am
suggesting that there should be only one definition: the one in a.h.
That is OK if the definition has inline linkage.  It is certainly not an
ODR violation, as there is only one definition.

Ian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux