473,659 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What gets inlined?

I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.

Suppose I have something like this (which, BTW is currently broken in
Qt-4-rc1):

inline QWidget* vBox(QWidget* parent) {
QWidget* box = new QWidget(parent) ;
QVBoxLayout* boxLayout = new QVBoxLayout(box );
box->setLayout(boxL ayout);
return box;
}

Clearly, there will be a lot happening between the entry point, and the
return from the function. My understanding is that all of the object code
involved will not be inlined, and only the compiled representation of the
function calls will be placed inline. Is this correct?
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #1
15 1478
* Steven T. Hatton:
I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.

Suppose I have something like this (which, BTW is currently broken in
Qt-4-rc1):

inline QWidget* vBox(QWidget* parent) {
QWidget* box = new QWidget(parent) ;
QVBoxLayout* boxLayout = new QVBoxLayout(box );
box->setLayout(boxL ayout);
return box;
}

Clearly, there will be a lot happening between the entry point, and the
return from the function. My understanding is that all of the object code
involved will not be inlined, and only the compiled representation of the
function calls will be placed inline. Is this correct?


No. Essentially you can't assume anything. And that's a FAQ:

<url: http://www.parashift.c om/c++-faq-lite/inline-functions.html# faq-9.3>

If you want optimization, tell your compiler to optimize.

If you want control over inlining, which is something else, use
compiler-specific language extensions.

--
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 #2
Steven T. Hatton wrote:
I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.


Yes. You can expect to be able to define it in multiple translation units
without getting an error. However, you can't assume any inlining to happen
or not happen.

Jul 23 '05 #3
Rolf Magnus wrote:
Steven T. Hatton wrote:
I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a
function.


Yes. You can expect to be able to define it in multiple translation units
without getting an error. However, you can't assume any inlining to happen
or not happen.


My question has to do with _what_ gets inlined _if_ the compiler inlines the
function? I suspect that doesn't vary a lot between implementations , but I
could be wrong.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #4
Everywhere that the inlined function is visible the function call gets
replaced by the code in the function with appropiate substitutions for
return value and the passed variable(s).

Jul 23 '05 #5
Keep forgetting that Google quick reply chucks out the reply to text so
here again:
My question has to do with _what_ gets inlined _if_ the compiler inlines the
function? I suspect that doesn't vary a lot between implementations , but I
could be wrong.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell


If inline occurs the following:
Everywhere that the inlined function is visible the function call gets
replaced by the code in the function with appropiate substitutions for
return value and the passed variable(s).

Jul 23 '05 #6
ve*********@hot mail.com wrote:
Everywhere that the inlined function is visible the function call gets
replaced by the code in the function with appropiate substitutions for
return value and the passed variable(s).


What happens when the inlined function has calls to other functions? I
believe it is correct to assume that the object code for these functions
is /not/ inlined. Unless of course those functions are also declared
inline, and the compile feels like doing it.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #7
ve*********@hot mail.com schreef:
Everywhere that the inlined function is visible ( and possibly other places as well ) the function call gets replaced ( it the compiler follows your hint) by the code in the function ( or parts of it, e.g. if the compiler can't inline everything) with appropiate substitutions for return value and the passed
variable(s).


It's very much a hint to the compiler. What it does with such a hint
is intentionally obscure. E.g. I'd expect a very good compiler not to
inline a catch(...) clause. That's typically cold code, keep that in
a separate function but do inline the try{ } body.

HTH,
Michiel Salters

Jul 23 '05 #8

"Steven T. Hatton" <ch********@ger mania.sup> wrote in message
news:Ot******** ************@sp eakeasy.net...
ve*********@hot mail.com wrote:
Everywhere that the inlined function is visible the function call gets
replaced by the code in the function with appropiate substitutions for
return value and the passed variable(s).


What happens when the inlined function has calls to other functions? I
believe it is correct to assume that the object code for these functions
is /not/ inlined. Unless of course those functions are also declared
inline, and the compile feels like doing it.


Whether the compiler will inline & substitute also subsequent function calls
in inlined functions is at the mercy of your compiler. There is no general
rule for this.

Cheers
Chris
Jul 23 '05 #9
"Steven T. Hatton" <ch********@ger mania.sup> wrote in message
news:f7******** ************@sp eakeasy.net
I know this is, to some extent, implementation dependent, but since
the Standard specifies an inline specifier, there must be some
"reasonable assumptions" I can make about what should happen when I
inline a function.

Suppose I have something like this (which, BTW is currently broken in
Qt-4-rc1):

inline QWidget* vBox(QWidget* parent) {
QWidget* box = new QWidget(parent) ;
QVBoxLayout* boxLayout = new QVBoxLayout(box );
box->setLayout(boxL ayout);
return box;
}

Clearly, there will be a lot happening between the entry point, and
the return from the function. My understanding is that all of the
object code involved will not be inlined, and only the compiled
representation of the function calls will be placed inline. Is this
correct? --

Generally, yes, unless the functions called are themselves inline functions.

Lots of people in these threads talk about it being "all up to the compiler"
to inline or not inline as it sees fit. With VC++, there is a switch that
turns on "auto-inlining", whereby the compiler can inline any function it
wants. With the default settings, however, no function is inlined unless the
inline keyword is used (or the function definition is in the class
declaration, since this is equivalent to using the inline keyword), i.e.,
use of the inline keyword is a necessary, though not sufficient, condition
for a function to be inlined. For other compilers, I guess you have to
consult their documentation.

--
John Carson

Jul 23 '05 #10

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

Similar topics

43
6867
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's another story.) The data is written once and then read many times. Each primitive read requires unboxing. The data reads are critical to overall app performance. In the hopes of improving performance, we have tried to find a way to avoid the...
5
2048
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 some investigating, I narrowed this down to a very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is declared as __declspec(dllimport) derives from a template, that template's methods are never inlined, even if declared with...
21
1338
by: Mahesh Devjibhai Dhola [MVP] | last post by:
Hi, I have added few of the events in some control, example code is: btnControl.GotFocus +=new EventHandler(EventHandlingMethod); btnControl.Click +=new EventHandler(EventHandlingMethod); lblControl.Click +=new EventHandler(EventHandlingMethod); private void EventHandlingMethod(object sender, EventArgs e) { ....... }
4
1109
by: sks | last post by:
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; }
2
1277
by: Michael Nemtsev | last post by:
AFAIK, method could be candidate for inlining. But is it possible to view after compiling that method became inlined? Are there some keywords in ILDASM that can show that method is inlined? --- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche
9
2655
by: Bilgehan.Balban | last post by:
Hi, If I define an inline function in one .c file, and use it from another, after compiling and linking the two, it seems the function is not inlined but rather called as a regular function. I would expect to see it inlined during linkage of the two object files. Does inlining only occur if the inline function is defined within the same file that it is called? Thanks,
2
1545
by: newbie | last post by:
I happened to read boost library code and realized that most (the part I read) functions are inlined like: template <class Key> inline void Foo(const Key& k) { ... ... } Is there a strong reasoning behind this?
4
2064
by: Zytan | last post by:
Can I force a function to NEVER be inlined? I want the call stack returned by: System.Diagnostics.StackTrace callStack = new System.Diagnostics.StackTrace(); to be such that: System.Diagnostics.StackFrame frame = callStack.GetFrame(0); is the function itself, NOT the function's caller (due to a release build making the function inlined into its caller)!
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8629
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2757
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 we have to send another system
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.