As specified in the Standard
If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier
extern
.
But function specifier part gives inline
function semantic as follows:
Any function with internal linkage can be an inline function. For a function with external linkage, the following restrictions apply: If a function is declared with an inline function specifier, then it shall also be defined in the same translation unit. If all of the file scope declarations for a function in a translation unit include the inline function specifier without
extern
, then the definition in that translation unit is an inline definition.
Case 1.
static inline void test(void){ //internal linkage, can be an inline function
printf("Test\n");
}
inline void test(void); //does it provide an external definition?
Case 2.
static inline void test(void){ //internal linkage, can be an inline function
printf("Test\n");
}
extern inline void test(void); //does it provide an external definition?
Case 3.
static inline void test(void){ //internal linkage, can be an inline function
printf("Test\n");
}
void test(void); //does it provide an external definition?
I have a confusion regarding the three cases. Are there differences between them? I currently think about them as
Case 1 -- does not provide an external definition (inline
without extern
)
Case 2 -- provides external definition (inline
with extern
)
Case 3 -- provides external definition (same as with extern
)
inline
function and when not to use it? • Isinline
withoutstatic
orextern
ever useful in C99? •extern inline
• What is the use of theinline
keyword in C? – Jonathan Leffler