473,835 Members | 1,778 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 #1
55 2798

"ben" <be******@hotma il.com> skrev i en meddelelse
news:42******** **************@ news.optusnet.c om.au...
is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?

ben

According to the C++ standard, inlining is at the discretion of the
compiler. It might thus inline a function that is not marked as "inline" and
it might not inline a function marked as "inline". Various compilers allow
you to override that one way or another, e.g. by using compilerswitche s or
by using special keywords such as __forceinline.
The purpose of inline for the user point of view is to avoid errors with
multiple definitions.

/Peter
Jul 23 '05 #2
The inline keyword is a hint, just like register. The compiler is free
to ignore it entirely. As such, functions without an inline keyword (or
defined outside of a class declaration) may be inlined if it meets some
unspecified internal heuristics. How a compiler optimizes code is
implementation-dependent.

Jul 23 '05 #3
ben wrote:
is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?

A compiler is free to inline whatever function it wants. Keyword inline is provided
because compilers aren't smart enough in general, and a user can aid the compiler to this
(but still the compiler is free to ignore the suggestion).

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4
ben
Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?

ben

"James Daughtry" <mo*******@hotm ail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
The inline keyword is a hint, just like register. The compiler is free
to ignore it entirely. As such, functions without an inline keyword (or
defined outside of a class declaration) may be inlined if it meets some
unspecified internal heuristics. How a compiler optimizes code is
implementation-dependent.

Jul 23 '05 #5
ben wrote:
Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?


We use inline to avoid the time cost of continuous function calls. In general, the usual
candidates are frequently called, small functions.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #6
* ben:
[top-posting]
Please don't top-post in this group -- corrected.

James Daughtry:
The inline keyword is a hint, just like register. The compiler is free
to ignore it entirely. As such, functions without an inline keyword (or
defined outside of a class declaration) may be inlined if it meets some
unspecified internal heuristics. How a compiler optimizes code is
implementation-dependent.


Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?


See Peter Koch Larsen's reply.

Do not rely on 'inline' as an optimization hint.

The keyword has nothing to do with 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 #7


ben wrote:
Ok, now, under what circumstances should I flag the keyword inline? What are
the likely candidates for inlining?


Use inline when your profiler indicates that having the function outline
is a bottleneck. As someone said small functions called within tight
loops are a potential candidate, but small functions per se aren't.
Jul 23 '05 #8

"ben" <be******@hotma il.com> wrote in message
news:42******** **************@ news.optusnet.c om.au...
is it true that a function without an inline keyword never get inlined? If
not true when is it inlined or not?

ben


A function can be inlined either by indicating the word inline or if it is
defined in the context of the class definition. As already pointed out by
others the keyword is simply a hint for the compiler, although if I recall
correctly there were old compilers that did not inline functions that were
not explicitly flagged with inline. For a more in-depth discussion what can
be inlined and what the compiler has to consider you can take a look at the
posting "How to force 'inline' with GCC or ICC" originating around the 15th
of May.

HTH
Chris
Jul 23 '05 #9
> What are the likely candidates for inlining?
Teeny tiny functions that would otherwise be written inline if there
weren't a need for some form of genericity. Follow this link for a
detailed analysis of why to avoid inline until you know that it buys
you something:

http://www.gotw.ca/gotw/033.htm

Jul 23 '05 #10

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

Similar topics

17
2356
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 much of it in VB if there's going to be a noticeable performance hit. So: 1. Does the VB compiler sometimes inline simple functions? 2. Is there much of a performance hit on a function call? Thanks.
6
1643
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 news for me. glen
10
2345
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 bounded or user-time bounded (i.e. windows based applications) but they are concurrently involved in the execution of the same parallelized task (i.e. a matrix-matrix multiplication), we must ensure that the advantage obtained by the parallelization...
4
1825
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 compile time, definitions of these functions, unlike other definitions, cannot be separately compiled and must be placed in header files. This creates a problem if the compiler does not actually inline a
11
2330
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 always expanded inline. Recently, I replaced an explicitly written function with one implemented using templates (and partial-template specialisation), in the belief that the the latter would be entirely inlined-away by the compiler, leaving the
25
2032
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 function? i.e compiler may choose not to inline certain inline function, but is it free to choose a non inline function to inline it? I have some simple one line get function, and index operators which I want to get inlined. But due to some problem...
21
1804
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 inline in their respective classes, can I expect the compiler to try and inline them all? obj.GetSize()
15
3072
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
1898
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 to vector3; //this conversion just returns positon Vector3 position;
0
9652
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10808
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
10520
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
10233
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...
1
7766
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
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...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4433
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
3
3088
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.