In message < >
(Daniel Vallstrom) wrote:
> Here is an example of what one might want to write:
>
> <start file1.h>
> inline int file1_f( int k );
>
> <end file1.h>
>
> <start file1.c>
> static inline int g( int k )
> {
> return k+1;
> }
>
> inline int file1_f( int k )
> {
> return 2*k + g(k);
> }
>
> <end file1.c>
>
>
> Why isn't this allowed? If the g call in file1_f is inlined
> there is no problem? And if the g call isn't inlined why
> can't the compiler choose to not inline file1_f calls, or
> for that matter choose to inline file1_f calls and handle
> the g call in some way? What's the problem?
It's well weird coding practice, what you've done there. And that's
kind of why it's disallowed. You wouldn't put the definition of
file_f in file1.c - you would normally put it in file1.h, so every function
including file1.h could have an inline definition.
Indeed, anyone just including file1.h as it stands would get a diagnostic
if they didn't provide their own inline definition...
So, if the inline definition (which would normally be in the header file)
used a static function, then that would normally indicate a programming
error, as it would imply that you weren't actually providing the same
functionality as the inline definition in another translation unit.
Now, let's say that file1_f is actually providing the external definition
of file_f, so you write:
extern inline int file1_f( int k )
{
return 2*k + g(k);
}
Now that would be legal. The external definition of file_f is allowed to
be different, and is allowed to reference static functions.
The diagnostic in question is a real pain to produce, as it doesn't
follow naturally from the code generation. Especially as you have to
defer generating it until you've read the whole file and know for certain
that you have an inline definition and not an external one.
--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW:
http://www.tematic.com/