Discussion:
question about static inline
(too old to reply)
pplppp
2004-06-24 11:40:21 UTC
Permalink
1. I read from "Using GNU CC" that a non-static inline function is
always ompiled on its own in the usual fashion, does CC for SCO
Unixware treats non-static inline functions the same way?

2. the man page for CC says the compiler would 'inline' some functions
even if the programmer didn't explicitly declared the function as
inline, so are one-line non-static functions 'inline'd ?

3. I have the declaration of class Foo in a header file, and a public
member function which I made it a static inline function. But when I
try to put in the definition for the function in the C file, the
compiler complains about the storage class is not defined or
something.

Foo.h
class Foo
{
public:
static inline void boo();
}

Foo.C
static inline void Foo::boo()
{
printf("Foo::boo\n");
}

If I remove the static modifier in the C file the compiler doesn't
complain. So I would like to know why the compiler complained and when
it doesn't complain after I removed the static modifier. I'm using CC
for SCO Unixware

thanks in advance

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
J. L. Schilling
2004-06-24 18:53:58 UTC
Permalink
Post by pplppp
1. I read from "Using GNU CC" that a non-static inline function is
always ompiled on its own in the usual fashion, does CC for SCO
Unixware treats non-static inline functions the same way?
Not sure what you mean by "non-static" (see answer to #3).
Can you provide a short example of what you're interested in?
Post by pplppp
2. the man page for CC says the compiler would 'inline' some functions
even if the programmer didn't explicitly declared the function as
inline, so are one-line non-static functions 'inline'd ?
No. By default, the only functions inlined except by request are
internal, compiler-generated functions. Only with the non-default
-Kinline option does the compiler try to inline user functions that
weren't coded as inline.
Post by pplppp
3. I have the declaration of class Foo in a header file, and a public
member function which I made it a static inline function. But when I
try to put in the definition for the function in the C file, the
compiler complains about the storage class is not defined or
something.
Foo.h
class Foo
{
static inline void boo();
}
Foo.C
static inline void Foo::boo()
{
printf("Foo::boo\n");
}
If I remove the static modifier in the C file the compiler doesn't
complain. So I would like to know why the compiler complained and when
it doesn't complain after I removed the static modifier. I'm using CC
for SCO Unixware
The two uses of "static" here are opposite: the one in Foo.h says
that boo is a static member function (no this point, accessed by Foo::boo,
etc.), while the one in Foo.c says boo has static linkage, meaning it
isn't global. Too different things and incompatible. GNU g++ also
gives an error on this.

Jonathan Schilling
Francis Glassborow
2004-06-24 23:38:50 UTC
Permalink
Post by pplppp
Foo.h
class Foo
{
static inline void boo();
}
Foo.C
static inline void Foo::boo()
{
printf("Foo::boo\n");
}
Your two uses of static have different meanings. In the class definition
it means that the function is a class member function that dose not have
a this pointer, i.e. it does not depend on any instance data.

In the implementation file the static qualification means that the
declaration/definition is private to this file. I am surprised that the
compiler lets you get away with that. However given that it does, the
definition is only available in that TU and so is pretty useless.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Loading...