473,499 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on inlining

ben
is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?

ben
Jul 23 '05
55 2720
Alf P. Steinbach wrote:
As of compiler invocation, are you talking
about one additional file to compile while avoiding to recompile the rest when you decide
to change the definition, vs compile *all* the rest that make use of the function, once
you decide to modify the definition.

Parse error. I gather it's an attempt at phrasing a false dilemma? ;-)

In addition to the other things that I mentioned (that essentially boil down that the
points provided do not make much sense to me), in this way the compiler also has to parse
the same definitions more times than once, and thus making your above specific point of
having to parse an additional file(?!) having not much sense too.
--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #51
* Ioannis Vranos:
Alf P. Steinbach wrote:
As of compiler invocation, are you talking
about one additional file to compile while avoiding to recompile the rest when you decide
to change the definition, vs compile *all* the rest that make use of the function, once
you decide to modify the definition.

Parse error. I gather it's an attempt at phrasing a false dilemma? ;-)

In addition to the other things that I mentioned (that essentially boil down that the
points provided do not make much sense to me), in this way the compiler also has to parse
the same definitions more times than once, and thus making your above specific point of
having to parse an additional file(?!) having not much sense too.


I think that may be because you're thinking too much (or perhaps only)
about optimization.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #52
The question discussed is

* Ioannis Vranos:
why would someone want to place a function definition in a header file?

from which followed

* Ioannis Vranos: Alf P. Steinbach wrote:
* Ioannis Vranos:
This is a tool subject, and the discussion turns to providing
documentation by "hacking" the language.
Parse error.


Meaning, documentation is an entirely other subject, and it has not anything to do with
our subject. It is a matter of what documentation style one wants, and documentation tools.


Yes, it is a matter of documentation style, and no, that doesn't mean it
has nothing to do with the subject.

Remove

* The comment (can't be checked by the compiler)
* The #include.
* The repeated declaration of the function signature.

Move

* The body of the function to the header file.

Add

* 'inline'.

Now the function (assuming it's a small one) is self-documenting.

Sorry but I can't understand this. For me the function definition remains the same
"self-documenting" (whatever this means) when you place it in one implementation file only.


With the definition in the header file you need only look at the header
file.

With the definition in a separate implementation file you may need to look
in two files, and the comment(s) in the header file may be inconsistent with
the separate implementation.

For some functions that is a good reason for some programmers to put the
definition in the header file.

When you only have a header file, no implementation file, there is one
less file to compile separately.


The first time. In the case of inlined functions however, the second time
you will have to recompile *all* the other files that make use of the function.


Yes, and (1) there's no need to remind me of what I have written by
reflecting it back in distorted form, and (2) there is a difference between
a file being compiled and a necessery compiler invocation; the latter can be
a cost both in build time (which I suspect is the only aspect you've
considered?) and in convenience and programmer effort.

Did you understand this now?

It is not primarily about build or program execution efficiency.

It cuts down on _redundancy_ of declarations, the repeated function
signatures.

Redundancy is bad both because of more work, and because of the
possibility of unnoticed differences.


You place the declaration only once, inside the same header that you would place the
redundant inlined definition, and include it as you would do in your (strange) inlining
approach. And you avoid the recompile-all when you modify the function definition.


Sorry, I can't figure out what you mean here.

As of compiler invocation, are you talking
about one additional file to compile while avoiding to recompile the rest when you decide
to change the definition, vs compile *all* the rest that make use of the function, once
you decide to modify the definition.


Parse error. I gather it's an attempt at phrasing a false dilemma? ;-)


I think the parser is buggy, and not the data itself. :-)


It would be nice if you attempted to present the data in a more
understandable way, so that this buggy parser can cope with it.
[
Please don't cut quoting so that what remains is without meaning.

Reinserted:

Ioannis:
"it will inline whenever it can for the ones that you defined as inline and
have placed in scope before the function use in a translation unit"
]
No, that is incorrect.

The point that's been stressed (I feel) a thousand times in this thread
is that not only can you not rely on that.

With modern compilers you can rely on the opposite: that the compiler
will do the job much better you can, and the more information you give
the compiler to do that job, the better job it does.


I have parse error myself here. By making it inline when you think that there will be
specific benefit for the program if the function gets inline, you do give more information
to the compiler.


No, making something inline is not necessarily about "when you think there
will be ... a benefit ... if [it's inlined]".

That is, by the way, invalid reasoning in more than one way. Consider your
reasoning here: "[the compiler] will inline [machine code] wherever it can
because you're making [the source code] [textually] inline where you think
there will be a benefit if the machine code is inlined." The compiler is
not guessing your intentions, and your intentions are not e.g. mine.

Presumably the parse error is simply because you cut away the statement that
"that is incorrect" referred to.

...

Major Error: I cant comprehend your points.

Aborted.


Try:

* Better quoting, with more context, less irrelevant quoted, fewer
spurious line breaks, fewer empty lines, fewer very long lines.

* Thinking about OTHER things than optimization.

Cheers, and hope this helps,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #53
Alf P. Steinbach wrote:
I think that may be because you're thinking too much (or perhaps only)
about optimization.

Actually you made an argument about compile-time optimisation or something. :-)
It would help much, if you provided a summary table of your points regarding benefits that
inline provides other than inlining. :-)

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #54
On Wed, 25 May 2005 08:03:30 -0700, E. Robert Tisdale wrote:
Alf P. Steinbach wrote:
Forgot one important there: the trend towards template oriented
programming.


TOP?


Don't say that too loud.

Jul 23 '05 #55
Alf P. Steinbach wrote:
It cuts down on _redundancy_ of declarations, the repeated function
signatures.

Redundancy is bad both because of more work, and because of the
possibility of unnoticed differences.


You place the declaration only once, inside the same header that you would place the
redundant inlined definition, and include it as you would do in your (strange) inlining
approach. And you avoid the recompile-all when you modify the function definition.

Sorry, I can't figure out what you mean here.

--somefunc.h

void somefunc();

--somefunc.cpp

#include "somefunc.h"

void somefunc()
{
// ...
}

--someotherfile.cpp

#include "somefunc.h"

// ...


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #56

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

Similar topics

17
2333
by: Tony Vitonis | last post by:
From what I can tell, VB.NET doesn't allow programmers to say explicitly that they want a function to be inlined. Now, I'm a big fan of factoring out duplicate code, but I don't want to do too...
6
1615
by: glen_stark | last post by:
Hi. I'm just curious if there any warnings or caveats or whatever to be aware of when inlining function object calls? If the answer is no, they inline just like everything else, that's good...
10
2304
by: gianguz | last post by:
The question is about the possible use of inlining to improve performance in a heavy multithreading environment (200+ threads). If we have to work with applications in which threads aren't I/O...
4
1802
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at...
11
2307
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...
25
1985
by: toton | last post by:
Hi, As inline is not mandetory, it depends on compiler to inline certain function (or using switch like fior GCC), my question is there any scope for inlining when it is not declared as inline...
21
1772
by: LuB | last post by:
How judicious ought one be when inlining small methods. I once read that in general, most compiles will only inline 'one' level. IE: if all the following methods were declared/defined as...
15
3022
by: Lloyd Dupont | last post by:
I have some code which looks like that: public CornerStyle RectCornerMode { get { return this.GetValue<CornerStyle>(); } set { this.SetValue<CornerStyle>(value); } }
10
1872
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
7131
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,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.