home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!unipalm!uknet!mcsun!sunic!seunet!appli!niklas
- From: niklas@appli.se (Niklas Hallqvist)
- Newsgroups: comp.lang.c++
- Subject: Re: GCC2.2 doesn't inline template class functions. Normal?
- Message-ID: <2139@appli.se>
- Date: 26 Aug 92 21:53:05 GMT
- References: <ANSTEY.92Aug26014202@sunspot.clarkson.edu>
- Distribution: comp.lang.c++
- Organization: Applitron Datasystem AB, GOTHENBURG, SWEDEN
- Lines: 53
-
- anstey@sun.soe.clarkson.edu (Charles Anstey) writes:
-
- :While playing around with GCC2.2, I noticed that it does not inline
- :template class member functions. Is this typical of all compilers for
- :reasons I do not know? GCC2.2 will inline member functions of a
- :non-template class.
-
- :The examples was quite simple.
- :template <class PT>
- :class S {
- :private:
- : PT length;
- :public:
- : S (int size):length(size) {};
- : PT size () { return (length);};
- :};
-
- :S.size() is not inlined. If I remove the template PT and change it to 'int'
- :then it is inlined.
-
- :Anyone know why?
-
- This is from memory, I don't have access to my compiler for the moment
- so I can't test it. If you instantiate a template class inside a function,
- the member functions gets queued up for compilation after the current one.
- If you refer to these members in this function you will get out-of-line
- calls, but calls in later functions will be inlined. The reason for this
- is simply compiler simplicity. When someone has the time, GCC might be
- changed to compile members directly during instantiation, pushing the
- current function's context on some stack. Example:
-
- int foo()
- {
- S<int> s(1);
- return s.size(); // Out of line
- }
-
- int bar()
- {
- S<int> s(1);
- return s.size(); // Inline
- }
-
- If this is wrong, try the same example with an explicit inline keyword
- on the size member function. As I said, I don't remember the exact details,
- I will check tomorrow.
-
- Niklas
- --
- Niklas Hallqvist Phone: +46-(0)31-40 75 00
- Applitron Datasystem Fax: +46-(0)31-83 39 50
- Molndalsvagen 95 Email: niklas@appli.se
- S-412 63 GOTEBORG, Sweden mcsun!seunet!appli!niklas
-