473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

inline and ctor

Can a ctor be declared inline ?

Is it not declared inline to avoid executable code size becoming
huge ?

kindly clarify

Thanks
V.Subramanian
Nov 23 '07 #1
12 1714
On Thu, 22 Nov 2007 23:53:29 -0800 (PST), su**************@yahoo.com wrote:
Can a ctor be declared inline ?
Yes.

Is it not declared inline to avoid executable
code size becoming huge ?
That may be a motive for someone.

--
Joel Yliluoma - http://iki.fi/bisqwit/
Nov 23 '07 #2
On Nov 23, 8:53 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Can a ctor be declared inline ?
Of course.
Is it not declared inline to avoid executable code size
becoming huge ?
Usually, it's not declared inline to avoid unnecessary coupling.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 23 '07 #3
On Nov 23, 10:01 pm, James Kanze <james.ka...@gmail.comwrote:
On Nov 23, 8:53 am, "subramanian10...@yahoo.com, India"

<subramanian10...@yahoo.comwrote:
Can a ctor be declared inline ?

Of course.
Is it not declared inline to avoid executable code size
becoming huge ?

Usually, it's not declared inline to avoid unnecessary coupling.
Just curious, but coupling to what? I don't quite understand this.
Isn't the compiler obligated with ensuring that an inlined and non-
inlined function call are for the most part equivalent? To what
degree can an inlined function digress from a non-inlined version?

Or is it because that inline functions must be declared somehow in
each source file that uses the function (in this case a ctor), and
will typically be placed in a header, which arguably is the "wrong"
place to put the details of the code?
Nov 23 '07 #4
On Nov 23, 3:53 pm, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Can a ctor be declared inline ?

Is it not declared inline to avoid executable code size becoming
huge ?
Note that inlining does not *always* increase executable code size.
It *may* reduce code size; it may increase code size. Please see:
http://www.parashift.com/c++-faq-lit...s.html#faq-9.3
Nov 23 '07 #5
On Fri, 23 Nov 2007 06:08:02 -0800, alan wrote:
On Nov 23, 10:01 pm, James Kanze <james.ka...@gmail.comwrote:
>On Nov 23, 8:53 am, "subramanian10...@yahoo.com, India"

<subramanian10...@yahoo.comwrote:
Can a ctor be declared inline ?

Of course.
Is it not declared inline to avoid executable code size becoming huge
?

Usually, it's not declared inline to avoid unnecessary coupling.
Just curious, but coupling to what? I don't quite understand this.
Isn't the compiler obligated with ensuring that an inlined and non-
inlined function call are for the most part equivalent? To what degree
can an inlined function digress from a non-inlined version?
All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which wouldn't
be necessary if they weren't inline.

--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
Anybody who doesn't cut his speed at the sight of a police car is
probably parked.
Nov 23 '07 #6
On Nov 24, 3:15 am, "Tadeusz B. Kopec" <tko...@NOSPAMPLEASElife.pl>
wrote:
On Fri, 23 Nov 2007 06:08:02 -0800, alan wrote:
On Nov 23, 10:01 pm, James Kanze <james.ka...@gmail.comwrote:
On Nov 23, 8:53 am, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.comwrote:
Can a ctor be declared inline ?
Of course.
Is it not declared inline to avoid executable code size becoming huge
?
Usually, it's not declared inline to avoid unnecessary coupling.
Just curious, but coupling to what? I don't quite understand this.
Isn't the compiler obligated with ensuring that an inlined and non-
inlined function call are for the most part equivalent? To what degree
can an inlined function digress from a non-inlined version?

All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which wouldn't
be necessary if they weren't inline.
I see; I suppose I haven't actually been on anything like a big C++
project (possibly involving library-in-binary-format), so I personally
don't care about recompilation; but I suppose this is a good idea, if
ever I get into one.
Nov 23 '07 #7
Tadeusz B. Kopec wrote:
All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which wouldn't
be necessary if they weren't inline.
It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular
"inline" keyword and define it elsewhere.
Nov 24 '07 #8
On Sat, 24 Nov 2007 08:16:40 -0500, Ron Natalie wrote:
Tadeusz B. Kopec wrote:
>All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which
wouldn't be necessary if they weren't inline.
It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular "inline"
keyword and define it elsewhere.
3.2.3 An inline function shall be defined in every translation unit in
which it is used.

So that 'elsewhere' usually is in the same header. Other places are hard
to maintain.

--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
There's a way out of any cage.
-- Captain Christopher Pike, "The Menagerie" ("The Cage"),
stardate unknown.
Nov 24 '07 #9
Tadeusz B. Kopec wrote:
On Sat, 24 Nov 2007 08:16:40 -0500, Ron Natalie wrote:
>Tadeusz B. Kopec wrote:
>>All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which
wouldn't be necessary if they weren't inline.
It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular "inline"
keyword and define it elsewhere.

3.2.3 An inline function shall be defined in every translation unit in
which it is used.

So that 'elsewhere' usually is in the same header. Other places are hard
to maintain.
Nope. Only the places where it is used. Public methods are one
thing, but you said "all inline members" and there's no necessity to
expose them all if they can't be called everywhere the class
definition appears.
Nov 24 '07 #10
On Nov 24, 2:16 pm, Ron Natalie <r...@spamcop.netwrote:
Tadeusz B. Kopec wrote:
All code which needs to 'see' a class definition has also to 'see' all
inline members. Changing any of them forces recompilation which wouldn't
be necessary if they weren't inline.
It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular
"inline" keyword and define it elsewhere.
Good point. I do occasionally make private functions inline,
for the obvious performance reasons, and when they are only
defined in the implementation source file, it doesn't introduce
any coupling either.

I'd never make a public or protected function inline, however,
unless the profiler said I had to.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 24 '07 #11
On Sat, 24 Nov 2007 10:13:04 -0500, Ron Natalie wrote:
Tadeusz B. Kopec wrote:
>On Sat, 24 Nov 2007 08:16:40 -0500, Ron Natalie wrote:
>>Tadeusz B. Kopec wrote:

All code which needs to 'see' a class definition has also to 'see'
all inline members. Changing any of them forces recompilation which
wouldn't be necessary if they weren't inline.

It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular
"inline" keyword and define it elsewhere.

3.2.3 An inline function shall be defined in every translation unit in
which it is used.

So that 'elsewhere' usually is in the same header. Other places are
hard to maintain.
Nope. Only the places where it is used. Public methods are one
thing, but you said "all inline members" and there's no necessity to
expose them all if they can't be called everywhere the class definition
appears.
Right. I didn't think about inline private members. Putting their code in
the class implementation file might be reasonable.

--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
Wherever you go...There you are.
-- Buckaroo Banzai
Nov 24 '07 #12
Tadeusz B. Kopec wrote:
On Sat, 24 Nov 2007 10:13:04 -0500, Ron Natalie wrote:
>Tadeusz B. Kopec wrote:
>>On Sat, 24 Nov 2007 08:16:40 -0500, Ron Natalie wrote:

Tadeusz B. Kopec wrote:

All code which needs to 'see' a class definition has also to 'see'
all inline members. Changing any of them forces recompilation which
wouldn't be necessary if they weren't inline.
>
It doesn't have to. While defining the function inside the class
definition makes it inline, you can still just use the regular
"inline" keyword and define it elsewhere.
3.2.3 An inline function shall be defined in every translation unit in
which it is used.

So that 'elsewhere' usually is in the same header. Other places are
hard to maintain.
Nope. Only the places where it is used. Public methods are one
thing, but you said "all inline members" and there's no necessity to
expose them all if they can't be called everywhere the class definition
appears.

Right. I didn't think about inline private members. Putting their code in
the class implementation file might be reasonable.
Reasonable and sensible, there is absolutely nothing to be gained by
defining private members in the header (with the possible exception of a
class with its member definitions spread over several compilation units).

--
Ian Collins.
Nov 24 '07 #13

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

Similar topics

1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
10
by: richardclay09 | last post by:
The output of this: #include <iostream> #include <vector> using namespace std; struct X { int i; X(const X& x) : i(x.i) { cout << "ctor copy: " << i << endl;
3
by: hazz | last post by:
will the third ctor in this class call the first two or just the null ctor? public class B { public B() { ... } public B(string str) {.....} public B(Token tkn, string str, int int_var) :...
5
by: PasalicZaharije | last post by:
Hallo, few days ago I see ctor like this: Ctor() try : v1(0) { // some code } catch(...) { // some code }
9
by: 2005 | last post by:
Hi If I have a class, class CNode { public: CarNode() : m_pNext(0), m_ticketNum(0) {} ~CarNode(); private:
8
by: Grizlyk | last post by:
Good morning. Look here: http://groups.google.com/group/fido7.ru.cpp.chainik/browse_frm/thread/7341aba5238c0f79 and here:...
5
by: peifeng_w | last post by:
Hi, try the following code with flag=0/1/2. #include<iostream> using namespace std; #define flag 2//option:0,1,2 class C {
3
by: John Salmon | last post by:
g++ complains about illegal access to a private member when the following is compiled with a private copy constructor for the class C. When the copy constructor is public, the program runs and...
2
by: subramanian100in | last post by:
If we do not provide any ctor for a class, the compiler provides the default ctor and copy ctor if needed. Consider a class Test. Suppose we provide some ctor in class Test but do not provide...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.