Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

external inline functions calling static inline functions

481 views
Skip to first unread message

jona...@vidyo.com

unread,
Feb 4, 2008, 9:01:24 PM2/4/08
to
Recent pre-release snapshots of gcc, and also Apple's gcc in MacOS
Leopard, warn about the following code:

-----------
static inline int foo() {
return 5;
}

inline int bar() {
return foo();
}
----

$ gcc -std=c99 -c inline-test.c
inline-test.c: In function 'bar':
inline-test.c:7: warning: 'foo' is static but used in inline function
'bar' which is not static


Is this code indeed a constraint violation?


(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.")


The actual inspiration for this question is Mac OS X's implementation
of the Posix ntohs() family of functions, which are implemented
(through various macro wrappers) as static inline functions; gcc thus
warns about any use of them in an external inline function.
Obviously, system headers aren't subject to the same conformance
constraints as user code. I'm trying, however, to determine whether
gcc should only suppress its warning for static inline functions
declared in a system header, or whether the warning is incorrect for
any calls to static inline functions.

--
Jonathan Lennox
jonathan at vidyo dot com

Douglas A. Gwyn

unread,
Feb 5, 2008, 11:37:24 AM2/5/08
to
jona...@vidyo.com wrote:
> static inline int foo() {
> return 5;
> }
> inline int bar() {
> return foo();
> }
> 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.")

Since "foo" has internal linkage, that constraint is violated.

> I'm trying, however, to determine whether
> gcc should only suppress its warning for static inline functions
> declared in a system header, or whether the warning is incorrect for
> any calls to static inline functions.

I think the system header ought to be fixed.

0 new messages