inline functions

P

puzzlecracker

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!
 
V

Victor Bazarov

puzzlecracker said:
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
 
P

puzzlecracker

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 said:
puzzlecracker said:
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
 
V

Victor Bazarov

puzzlecracker said:
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.
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
 
A

Andrew Koenig

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.
 
P

puzzlecracker

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.
 
V

Victor Bazarov

puzzlecracker said:
[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top