472,989 Members | 2,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

are all templates inlined?

sks
All,

I thought all template instantiations were inlined until I analyzed the
following code.

template<typename t>
class Something
{
public:
inline int getSomething() { return 1; }
int getAnother();
};

template<typename t>
int Something<t>::getAnother()
{
return 2;
}

(I may not have the syntax exactly correct here since I am not
copying/pasting the code that I tested at work today).

Anyway, when I analyzed the assembly code, the compiler generated a symbol
for "getSomething" but there wasn't one for "getAnother" (it seemed to be
inlined).

Can we conclude from this that all templates are not inlined?

Thanks.
Dec 6 '05 #1
4 1085
sks wrote:
I thought all template instantiations were inlined until I analyzed
the following code.

template<typename t>
class Something
{
public:
inline int getSomething() { return 1; }
'inline' here is superfluous. Any member function defined in the class
definition is inline.
int getAnother();
};

template<typename t>
int Something<t>::getAnother()
{
return 2;
}

(I may not have the syntax exactly correct here since I am not
copying/pasting the code that I tested at work today).
I thin you got the right syntax.
Anyway, when I analyzed the assembly code, the compiler generated a
symbol for "getSomething" but there wasn't one for "getAnother" (it
seemed to be inlined).
That's of no consequence here.
Can we conclude from this that all templates are not inlined?


No. Whatever one particular implementation does is immaterial, really.

Besides, when compiling this particular code, the compiler could throw
everything away. The code is not _used_, so the template is never
_instantiated_.

V
Dec 6 '05 #2
sks wrote:
All,

I thought all template instantiations were inlined until I analyzed the
following code.

template<typename t>
class Something
{
public:
inline int getSomething() { return 1; }
int getAnother();
};

template<typename t>
int Something<t>::getAnother()
{
return 2;
}

(I may not have the syntax exactly correct here since I am not
copying/pasting the code that I tested at work today).

Anyway, when I analyzed the assembly code, the compiler generated a symbol
for "getSomething" but there wasn't one for "getAnother" (it seemed to be
inlined).
Template instantiation is just like anything else--they are inline when
the compiler feels like to inline them.

Can we conclude from this that all templates are not inlined?
No. You generally cannot conclude base or symbol table.

Thanks.


Ben
Dec 6 '05 #3
sks

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:7t******************************@comcast.com. ..
sks wrote:
I thought all template instantiations were inlined until I analyzed
the following code.

template<typename t>
class Something
{
public:
inline int getSomething() { return 1; }


'inline' here is superfluous. Any member function defined in the class
definition is inline.
int getAnother();
};

template<typename t>
int Something<t>::getAnother()
{
return 2;
}

(I may not have the syntax exactly correct here since I am not
copying/pasting the code that I tested at work today).


I thin you got the right syntax.
Anyway, when I analyzed the assembly code, the compiler generated a
symbol for "getSomething" but there wasn't one for "getAnother" (it
seemed to be inlined).


That's of no consequence here.
Can we conclude from this that all templates are not inlined?


No. Whatever one particular implementation does is immaterial, really.

Besides, when compiling this particular code, the compiler could throw
everything away. The code is not _used_, so the template is never
_instantiated_.

V


I do call both methods for a particular template instantiation though.
I made a mistake on my original post. One of my paragraphs should have said:
' Anyway, when I analyzed the assembly code, the compiler DID NOT GENERATE a
symbol for "getSomething" but GENERATED ONE for "getAnother" '.
So, can I conclude that templates SOMETIMES are not inlined?

If I used the above approach of separating the implementation of a member
function from the class definition, then the symbol is generated for it,
however, if the implementation of the method is defined within the class
definition, like I did above, then it seemed to be inlined.

Thanks.


Dec 6 '05 #4
sks wrote:
[...]
So, can I conclude that templates SOMETIMES are not inlined?


Sure.

V
Dec 6 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Senthilraja | last post by:
I have the following program using templates. Someone please let me know the syntax to be used for defining the member functions push, pop etc. as non-inline functions. #include <iostream>...
1
by: leo | last post by:
I had the believe that the use of templates didn't affect performance. That is, that from the performance point of view it's the same: a) template <class X> class Y{ X attrib; ... };
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
11
by: Elpoca | last post by:
Hi: What rules govern the inlining of templated functions and templated class methods? It has always been my understanding that both templated functions and templated class methods were...
5
by: Eric Fortier | last post by:
Hi all, Last year I posted a message regarding templates use in blitter functions, but the single answer I got didn't help. My problem is that I was writing blitter functions which takes a...
8
by: collection60 | last post by:
Hi people, I want to use templates, for syntatic niceness only, not for doing similar operations on different types. The types I'm manipulating are basically just pointers. So if it's a pointer...
1
by: vsgdp | last post by:
If I define a member function inside the class definition, it is automatically inlined correct (or at least hinted to the compiler to make inline)? When defining a template class, you usually have...
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.