[gnu.g++.bug] static functions

keffer@SPERM.OCEAN.WASHINGTON.EDU (Tom Keffer) (09/10/89)

Michael,

	This goes back to an earlier discussion we had as to whether
-finline-functions should be the default.  Consider the following:

#ifdef DEBUG
#define Inline static
#else
#define Inline inline

class Foo {
	void bar();
};

Inline bar() { /* a definition */ }

This is how I have been using the inline qualifier: make it static if
you are debugging.  

Now the problem.  Cfront 2.0 squawks at this with the error "static
specified for qualified name bar()".  If the definition is static,
the declaration must be static (in which case "this" is not defined
under 2.0), clearly not what we mean here.  Personally, I think this
is stupid, but it's their compiler.  

So, the choice is whether to make g++ compliant, or ignore the whole
thing.  

A cavaet: I have not tested this myself because I do not have access
to a 2.0 compiler.  It is being passed on by a user of my vector
package.  

-tk

---
 Dr. Thomas Keffer          | Internet: keffer@sperm.ocean.washington.edu
 School of Oceanography     | BITNET:   keffer%sperm.ocean.washington.edu@UWAVM
 Univ. of Washington, WB-10 | uucp:     uw-beaver!sperm.ocean.washington.edu!keffer
 Seattle, WA 98195          | Telemail: T.KEFFER/OMNET
    (206) 543-6455

schmidt@zola.ics.uci.edu (Doug Schmidt) (09/10/89)

In article <8909092351.AA14187@sperm.ocean.washington.edu>, keffer@SPERM (Tom Keffer) writes:
>Michael,
>
>	This goes back to an earlier discussion we had as to whether
>-finline-functions should be the default.  
>

This reminds me...

Here's another relevant entry from the newly updated documentation from
g++.texinfo:

----------------------------------------
@item -fdefault-inline
If this option is enabled then member functions defined inside class
scope are compiled inline by default, @emph{i.e.,} you don't need to
add @var{inline} in front of the member function name.  If this option
is not enabled GNU C++ will not inline member functions by default.
----------------------------------------

Doug
--
schmidt@ics.uci.edu (ARPA) |   Per me si va nella citta' dolente.
office: (714) 856-4043     |   Per me si va nell'eterno dolore.
                           |   Per me si va tra la perduta gente.
                           |   Lasciate ogni speranza o voi ch'entrate.

tiemann@SUN.COM (Michael Tiemann) (09/10/89)

   Date: Sat, 9 Sep 89 16:51:31 PDT
   From: keffer@sperm.ocean.washington.edu (Tom Keffer)

   Michael,

	   This goes back to an earlier discussion we had as to whether
   -finline-functions should be the default.  Consider the following:

   #ifdef DEBUG
   #define Inline static
   #else
   #define Inline inline

   class Foo {
	   void bar();
   };

   Inline bar() { /* a definition */ }
Is what you really mean ``Inline void Foo::bar ();''.  If so I don't
see a problem with just #defining ``Inline'' to nothing, since the
return type will save your function from not having a return type.

Michael

keffer@SPERM.OCEAN.WASHINGTON.EDU (Tom Keffer) (09/11/89)

mt> Date: Sat, 9 Sep 89 19:07:32 PDT
mt> From: tiemann@Sun.COM (Michael Tiemann)
mt> Reply-To: tiemann@lurch.stanford.edu

mt>    Date: Sat, 9 Sep 89 16:51:31 PDT
mt>    From: keffer@sperm.ocean.washington.edu (Tom Keffer)

mt>    Michael,

mt> 	   This goes back to an earlier discussion we had as to whether
mt>    -finline-functions should be the default.  Consider the following:

mt>    #ifdef DEBUG
mt>    #define Inline static
mt>    #else
mt>    #define Inline inline

mt>    class Foo {
mt> 	   void bar();
mt>    };

mt>    Inline bar() { /* a definition */ }


mt> Is what you really mean ``Inline void Foo::bar ();''.

Yes, of course.  Sorry.

mt> If so I don't
mt> see a problem with just #defining ``Inline'' to nothing, since the
mt> return type will save your function from not having a return type.

mt> Michael

Sorry, I didn't make myself very clear.  All of the above code is in a
header file.  The intention is to make the definition of Foo::bar a
static function when debugging, inline when not.  If you don't make it
static, the linker will complain about multiple definitions.

Maybe there's a better way of doing this but, in any case, the two
compilers (cfront 2.0 and g++) handle this case differently.
Consider:

	class Foo {
	  STATIC void bar();
	};

	static void Foo::bar() { }

cfront 2.0 will declare an error if STATIC is #defined to nothing, g++
will not. 

Again, the cavaet.  This is being passed on from a user of my vector
package.  I have not verified it first hand.

-tk

---
 Dr. Thomas Keffer          | Internet: keffer@sperm.ocean.washington.edu
 School of Oceanography     | BITNET:   keffer%sperm.ocean.washington.edu@UWAVM
 Univ. of Washington, WB-10 | uucp:     uw-beaver!sperm.ocean.washington.edu!keffer
 Seattle, WA 98195          | Telemail: T.KEFFER/OMNET
    (206) 543-6455