[comp.lang.c++] Optimization of inline functions

cordova@minnie.tmc.edu (Jose Cordova) (03/31/91)

In article <1894@hpwala.wal.hp.com> boba@hpwarau.UUCP (Bob Alexander) writes:

>I realize that the C++ definition does not require the compiler to pay
>attention to the inline keyword, just as C compilers are not required to
>pay attention to the register keyword.  But is there a way to get TC++
>to compile inline?  Or, is there another way to have read-only class
>variables?

You might want to try the following and see if it makes any difference:

class Shmoo
   {
   public:
      int getCounter();
   private:
      int counter;
   }

inline int Shmoo::getCounter()
{
   return counter;
}


--
************************************************************************
Jose Cordova  - Department of Computer Science - Mississippi State Univ.
                     cordova@walt.cs.msstate.edu
************************************************************************

mike@taumet.com (Michael S. Ball) (04/01/91)

In article <1894@hpwala.wal.hp.com> boba@hpwarau.UUCP (Bob Alexander) writes:
>getCounter() is an inline function, so I should be able to read counter with
>no function call overhead.  But Turbo C++ 1.0 seems to always compile it
>as a CALL-ed function.  This makes me feel guilty each time I want

Perhaps you are compiling with debug.  Since debugging inlined and possiblly
optimized functions is extremely difficult, TD insists that inline functions
be laid down as normal functions.  Otherwise, TC++ will inline the function
unless it contains some "forbidden" constructs it can't handle.  In such
cases it issues a warning.  It always works when I do it.
-- 
Michael S. Ball			mike@taumet.com
TauMetric Corporation		(619)697-7607

psmith@iies.ecn.purdue.edu (Paul F Smith) (04/01/91)

In article <1894@hpwala.wal.hp.com> boba@hpwarau.UUCP (Bob Alexander) writes:
>
[example deleted]
>getCounter() is an inline function, so I should be able to read counter with
>no function call overhead.  But Turbo C++ 1.0 seems to always compile it
>as a CALL-ed function. 

In the IDE, somewhere under the options menu, there's an option to compile
inline functions out-of-line. I think this makes it easier to debug a program, 
then turn on inline when you've got it working. Maybe you have this selected. 
(although it wouldn't suprise me if the TC++ compile can't really do inline 
functions)

>
>  Bob Alexander                                         boba@hpwala.hp.com
>  -----------------------------------------------------------------------
>  Organizations don't have opinions: individuals do.  The opinions expressed
>  above do not necessarily reflect those of the stockholders, employees, or
>  directors of Hewlett-Packard.


--
------------------------------------------------------------------
Paul F. Smith - ADPC - Purdue University     psmith@ecn.purdue.edu
<someday I'll think of something profound to put here, maybe>

boba@hpwarau.hp.com (Bob Alexander) (04/02/91)

Michael S. Ball writes:
>>                       But Turbo C++ 1.0 seems to always compile it
>>as a CALL-ed function.  This makes me feel guilty each time I want
>
>Perhaps you are compiling with debug.

Aha!  That must be it.  I always have my debugging options turned on.
(Of course, if the debugging options are turned off, it's a lot harder
to disassemble the code via TD, so I'll just have to take it on faith
that the code was inlined. ;-)

Thank you.

- Bob Alexander