D
Daniel Vallstrom
Why does c99 require that inline functions with external linkage
must not refer to functions, possibly inline-specified, with
internal linkage? Here is the c99 text:
"6.7.4 Function specifiers
Syntax
function-specifier:
inline
Constraints
Function specifiers shall be used only in the declaration of an
identifier for a function. An inline definition of a function
with external linkage shall not contain a definition of a
modifiable object with static storage duration, and shall not
^^^^^^^^^^^^^
contain a reference to an identifier with internal linkage."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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?
I guess that compilers must give a diagnostic for constraint
violations but may produce a compiled program.
To be sure, when I run a program containing something like the
above example code through gcc and intel's icc, with -std=c99,
the program compiles just fine. gcc doesn't complain at all but
IIRC gcc states explicitly that their inline handling doesn't
follow the standard? icc gives the following warning:
"warning #1173: an entity with internal linkage cannot be
referenced within an inline function with external linkage"
but as said still compiles the program.
(I thought that this question must have been discussed
somewhere but I can't find an answer.)
Daniel Vallstrom
must not refer to functions, possibly inline-specified, with
internal linkage? Here is the c99 text:
"6.7.4 Function specifiers
Syntax
function-specifier:
inline
Constraints
Function specifiers shall be used only in the declaration of an
identifier for a function. An inline definition of a function
with external linkage shall not contain a definition of a
modifiable object with static storage duration, and shall not
^^^^^^^^^^^^^
contain a reference to an identifier with internal linkage."
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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?
I guess that compilers must give a diagnostic for constraint
violations but may produce a compiled program.
To be sure, when I run a program containing something like the
above example code through gcc and intel's icc, with -std=c99,
the program compiles just fine. gcc doesn't complain at all but
IIRC gcc states explicitly that their inline handling doesn't
follow the standard? icc gives the following warning:
"warning #1173: an entity with internal linkage cannot be
referenced within an inline function with external linkage"
but as said still compiles the program.
(I thought that this question must have been discussed
somewhere but I can't find an answer.)
Daniel Vallstrom