wrote:
> On Jul 31, 10:12 am, Ian Collins <ian-n...@hotmail.com> wrote:
>> jg wrote:
>>> On Jul 30, 8:47 pm, Neelesh Bodas <neelesh.bo...@gmail.com> wrote:
>>>> On Jul 31, 4:51 am, jg <jgu...@gmail.com> wrote:> Does C++ standard require an inline function be generated all the
>>>>> time ?
>>>> The correct term is "inlined", not "generated".
>>>> Given that, the answer is that the standard doesnot require an inline
>>>> function to be inlined all the time.
>>>> -N
>>> No. I mean "generated". Whether an inline function is inlined or not
>>> is not my question. My question is whether a compiler will generate
>>> the code for that inline function no matter whether the function
>>> is inlined or not.
>> The answer has to be yes, if the function is used. Code will either be
>> generated inline where it is called, or elsewhere if the compiler
>> decides not to inline the function.
>>
>> There is no requirement to generate a stand alone function.
>>
>> --
>> Ian Collins.
>
> Hi Jg,
> It is up to the compiler based on the size of the piece of
> inline code constructed by the programmer.
> If the compiler feels not to make the piece as inline(because of
> larger size), it does not generate the inline code.
I think you are all being a bit obtuse here. He is clearly asking
whether a (non-inlined) subroutine for the function will be generated
in the final binary regardless of whether the compiler inlined its
contents in the only place where it was called or not.
Or if we word it in another way: Even if the compiler inlined the
contents of the function at the calling location, will the contents
of the function also exist as a non-inlined function in the final
binary (even if this non-inlined version is never called anywhere)?
I don't know what the standard says, but IIRC at least gcc has a
command-line option to force it to create non-inlined instances of
inline functions regardless of whether they are necessary or not.