inline functions



 DEVELOP > c-Plus-Plus > inline functions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "puzzlecracker"
Date: 17 Jan 2005 11:18:28 AM
Object: inline functions
Is there a case where having an "inline function" is more effective and
less code i.e. code clean, but we still resort to use a regular
function for this purpose?
Another question, which I previously posted but answers were very
opinioned and not conclusive - Likely due to somewhat ambiguous
description in the first place. Sorry for repost!
If it is possible to use virtual inline functions/methods, where would
such case arise? Also could you explain the ballpark mechanics behind
it?
Thanks...
...wonna be a c++ guru, but still a neophyte!
.

User: "Victor Bazarov"

Title: Re: inline functions 17 Jan 2005 11:32:10 AM
puzzlecracker wrote:

Is there a case where having an "inline function" is more effective and
less code i.e. code clean, but we still resort to use a regular
function for this purpose?

I really have hard time understanding that question. In every particular
case you entertain certain goals. Those goals can call for conflicting
implementations. One says, "write inline functions", another can say,
"hide the implementation". You need to decide what's more important in
every particular case. So, the answer is probably "yes" to all questions
of this sort, "is there a case where blah".

Another question, which I previously posted but answers were very
opinioned and not conclusive - Likely due to somewhat ambiguous
description in the first place. Sorry for repost!

If it is possible to use virtual inline functions/methods, where would
such case arise? Also could you explain the ballpark mechanics behind
it?

Yes, it is possible. A [virtual] function called for an object of that
type is resolved statically. If it's inline (or can be inlined), a call
can be replaced with its body. So, even if you declare some function as
virtual, it still can be inlined when not used polymorphically. If, OTOH,
it _is_ bound dynamically (the compiler doesn't know the actual type of
the object), it cannot be inlined.
I am not sure what "ballpark mechanics" is. Are you talking about
stadiums with retractable roofs?

...wonna be a c++ guru, but still a neophyte!

You can never become a C++ guru by wanting to become one. There are no
courses that teach "guruness" or exams that, when passed, indicate
"guruness". Besides, wouldn't you rather simply earn good money with C++?
V
.
User: "puzzlecracker"

Title: Re: inline functions 17 Jan 2005 11:53:09 AM
Can I ask for an example of such case or, in your terms, what would be
the goal to NOT use the inline functions, were it used - the runtime
efficiency is preserved and less code?
A small follow-up to the second question (a sort of "what if"). If type
is resolved in runtime and in both classes (base and inherited) the
same function is declared inline virtual: would an error be issued or
compiler will simple NOT inline either of them?

Besides, wouldn't you rather simply earn good money with C++?

That is the GOAL. Could you suggest something that can compliment my
C++ knowledge to achieve heretofore mentioned objective?
Thanks so much!
Your knowledge base is impeccable!
P.S.: So, the change in paradigm to where the real catchphrase should
be -"wonna be a c++ moneymaker, but still a neophyte!"
Spasibo!
Victor Bazarov wrote:

puzzlecracker wrote:

Is there a case where having an "inline function" is more effective

and

less code i.e. code clean, but we still resort to use a regular
function for this purpose?


I really have hard time understanding that question. In every

particular

case you entertain certain goals. Those goals can call for

conflicting

implementations. One says, "write inline functions", another can

say,

"hide the implementation". You need to decide what's more important

in

every particular case. So, the answer is probably "yes" to all

questions

of this sort, "is there a case where blah".

Another question, which I previously posted but answers were very
opinioned and not conclusive - Likely due to somewhat ambiguous
description in the first place. Sorry for repost!

If it is possible to use virtual inline functions/methods, where

would

such case arise? Also could you explain the ballpark mechanics

behind

it?


Yes, it is possible. A [virtual] function called for an object of

that

type is resolved statically. If it's inline (or can be inlined), a

call

can be replaced with its body. So, even if you declare some function

as

virtual, it still can be inlined when not used polymorphically. If,

OTOH,

it _is_ bound dynamically (the compiler doesn't know the actual type

of

the object), it cannot be inlined.

I am not sure what "ballpark mechanics" is. Are you talking about
stadiums with retractable roofs?

...wonna be a c++ guru, but still a neophyte!


You can never become a C++ guru by wanting to become one. There are

no

courses that teach "guruness" or exams that, when passed, indicate
"guruness". Besides, wouldn't you rather simply earn good money with

C++?


V

.
User: "Victor Bazarov"

Title: Re: inline functions 17 Jan 2005 12:11:29 PM
puzzlecracker wrote:

Can I ask for an example of such case or, in your terms, what would be
the goal to NOT use the inline functions, were it used - the runtime
efficiency is preserved and less code?

Large functions when inlined hurt overall performance. Too much inlining
also can hurt overall performance (functions where inlined code is used
tend to become large themselves). Think cache misses on modern CPUs.

A small follow-up to the second question (a sort of "what if"). If type
is resolved in runtime and in both classes (base and inherited) the
same function is declared inline virtual: would an error be issued or
compiler will simple NOT inline either of them?

I would expect both functions to be called regularly. If the compiler
doesn't know which function to call, it has to resort to virtual function
mechanism. Since virtual function mechanism requires to take the address
of the function, it has to have a regular, out-of-line, so to speak, body.
There will be no error message. In any case, that's the implementation
detail, really. In theory, or according to the Standard requirements,
there is no difference in virtual function behaviour whether it's inline
or not.

Besides, wouldn't you rather simply earn good money with C++?



That is the GOAL. Could you suggest something that can compliment my
C++ knowledge to achieve heretofore mentioned objective?

Get a job that involves writing C++ code. It's not a guarantee, but it's
better that just studying. One can sometimes earn a living writing crappy
code but to earn good money one needs to get much better. Of course, as
always, knowing the basics in any particular application area never hurts
either.
V
.
User: "Andrew Koenig"

Title: Re: inline functions 17 Jan 2005 01:05:25 PM
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:mdTGd.36139$NC6.18317@newsread1.mlpsca01.us.to.verio.net...

Besides, wouldn't you rather simply earn good money with C++?

That is the GOAL. Could you suggest something that can compliment my
C++ knowledge to achieve heretofore mentioned objective?


Get a job that involves writing C++ code. It's not a guarantee, but it's
better that just studying. One can sometimes earn a living writing crappy
code but to earn good money one needs to get much better.

Alternatively, if your skills aren't yet marketable, you might consider
stopping asking questions about obscure corners of the language. If you
want to learn how to program well, your time would be better spent as
follows:
1) Pick a problem.
2) Write the best program you can possibly write to solve it.
3) Post the program here and ask for suggestions for improvement.
This technique will be more effective if you choose problems that can be
solved with small programs, but that's OK--you should know how to write
beautiful small programs before you try to work on larger ones.
.
User: "puzzlecracker"

Title: Re: inline functions 17 Jan 2005 01:50:29 PM
Are you http://c2.com/cgi/wiki?AndrewKoenig?
When they - skills - are consider being marketable?
I actually read quite a bit on C++, design patterns revealed, C++
primer 3rd edition, Standard Template library, Multithreaded
Programming in C++ by Mark Walmsley, many different online tutorials
and, of course, this forum. That is aside from college courses, such as
C++ programming language, etc. It just happens to be that I forget or
ignore some of the aspects while perusing the textbook. Thus, when I
encounter them, I'd like some clarification as this groups serves as
perfect outlet for just this purpose.
What kind of problem set you're referring to? Please be more
specific.
How strongly the design patterns are required at C++ market nowadays? I
understand most of them, but haven't really implemented on the large
scare or in the real world application. But, I do understand the inner
-workings of most of the them.
Thanks.
Andrew Koenig wrote:

"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:mdTGd.36139$NC6.18317@newsread1.mlpsca01.us.to.verio.net...

Besides, wouldn't you rather simply earn good money with C++?


That is the GOAL. Could you suggest something that can compliment

my

C++ knowledge to achieve heretofore mentioned objective?


Get a job that involves writing C++ code. It's not a guarantee,

but it's

better that just studying. One can sometimes earn a living writing

crappy

code but to earn good money one needs to get much better.


Alternatively, if your skills aren't yet marketable, you might

consider

stopping asking questions about obscure corners of the language. If

you

want to learn how to program well, your time would be better spent as
follows:

1) Pick a problem.

2) Write the best program you can possibly write to solve it.

3) Post the program here and ask for suggestions for improvement.

This technique will be more effective if you choose problems that can

be

solved with small programs, but that's OK--you should know how to

write

beautiful small programs before you try to work on larger ones.

.
User: "Victor Bazarov"

Title: Re: inline functions 17 Jan 2005 01:59:46 PM
puzzlecracker wrote:

[...]
When they - skills - are consider being marketable?

When you (and others) think you can put your abilities on your resume (CV)
when seeking employment AND when doing so doesn't damage your resume (CV).

[...]
How strongly the design patterns are required at C++ market nowadays?

Depends on the organization. Some couldn't care less about them. Market
is a rather large place with all kinds of requirements you can wish for.

[...]

And, please, don't top-post. Thanks.
V
.







  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER