473,661 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using inline

Hello experts!

I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that sound strange.

Here is the whole section:
It says" 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 function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined.,
and if they cannot be inlined, you must remove the inline specification."
My question is what does it mean with this This creates a problem if the
compiler does not actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined,
and if they cannot be inlined, you must remove the inline specification.

Many thanks

//Tony
Aug 11 '05 #1
5 1936
> Hello experts!

I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that sound strange.

Here is the whole section:
It says" 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.
inline is not a hard and fast rule that the compiler has to obey. Its
just a hint to the compiler. If the compiler decides to inline the call
to an inline function, its *definition* must be visible to the compiler
at the place of the call. This is why inline functions are usually
defined in the header files itself.
This creates a problem if the compiler does not
actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined.,
and if they cannot be inlined, you must remove the inline specification."

My question is what does it mean with this This creates a problem if the
compiler does not actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined,
and if they cannot be inlined, you must remove the inline specification.

I don't understand why the author has quoted it like this. Usually
there are gaurd directives for every header files that make sure that
the same header is not included more than once during the compilation
process.

#ifndef HEADER_FILENAME
#define HEADER_FILENAME

// ... Header file stuff here

#endif

So, it does not matter what the compiler decides with a call to an
inline function - there should be no problems of multiple definitions
of the function if the gaurd directives are in place. And there's no
way to check whether a call to an inline function will be actually
inlined or not. Its completely at the discretion of the compiler.
Many thanks

//Tony


HTH
Srini

Aug 11 '05 #2

Tony Johansson skrev:
Hello experts!

I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that sound strange.

Here is the whole section:
It says" 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 function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined.,
and if they cannot be inlined, you must remove the inline specification."
My question is what does it mean with this This creates a problem if the
compiler does not actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined,
and if they cannot be inlined, you must remove the inline specification.

Many thanks

//Tony


This means that your book is probably better used for non-reading
purposes. What is said is just plain wrong.

/Peter

Aug 11 '05 #3
Le jeudi 11 août 2005 à 15:00, Srini a écrit dans comp.lang.c++*:
My question is what does it mean with this This creates a problem if the
compiler does not actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined,
and if they cannot be inlined, you must remove the inline specification.

I don't understand why the author has quoted it like this. Usually
there are gaurd directives for every header files that make sure that
the same header is not included more than once during the compilation
process.

#ifndef HEADER_FILENAME
#define HEADER_FILENAME

// ... Header file stuff here

#endif

So, it does not matter what the compiler decides with a call to an
inline function - there should be no problems of multiple definitions
of the function if the gaurd directives are in place.


Hmm, I don't understand it that way. The compilation guards protect
against multiple inclusion of a header file in one compilation unit, but
the author seems to worry about the use of the header file in several
compilation units leading to several instances of the (not-)inlined
function in the linked binary.

Well, that would be a problem if the function name caused a "Symbol
multiply defined" error at link-time. I don't remember such a situation.

As for the function-code duplication, if that worries the programmer,
why would have happened if the inline keyword had been honored, anyway?
And there's no
way to check whether a call to an inline function will be actually
inlined or not. Its completely at the discretion of the compiler.


You may even get a mixture of both in your program, on a per-call basis.

--
___________ 11/08/2005 15:35:21
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
Aug 11 '05 #4
Tony Johansson wrote:

My question is what does it mean with this This creates a problem if the
compiler does not actually inline
a function (you may end up having multiple definitions of the same function)
Therefore, you have to check that the inline functions will actually be
inlined,
and if they cannot be inlined, you must remove the inline specification.


This is simply wrong. The compiler and linker team up to take care of
this. It sounds like you've found another book that you should get rid
of. <g>

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Aug 11 '05 #5
Tony Johansson wrote:
My question is,
"What does it mean with this This creates a problem
if the compiler does not actually inline a function
(you may end up having multiple definitions of the same function)
Therefore, you have to check that
the inline functions will actually be inlined,
and if they cannot be inlined, you must remove the inline specification.


It's just wrong.
Take this book back where you found it and get your money back.
Aug 11 '05 #6

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

Similar topics

13
31758
by: Mike | last post by:
We are using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> Using CSS (not html since align=center and <center> are deprecated) I can get it to work in IE6 (but not NS 7 or Firefox) with. <div style="text-align:center; display:block; "><img src="myimg.gif"
47
3852
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
3134
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with extern linkage is inlined? Should the compiler still export the function? Or is an inlined function implicitly static?
18
5051
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
6
3418
by: Anders M | last post by:
I'm trying to use Inline-code to call Page_load, Page_Init or Page_PreRender methods. I've also got a code behind c#-file. I can define inline methods for buttons and so on...that works fine. But when I try to call Page_load, Page_Init or Page_PreRender methods it doesn't work. Non of the methods get's triggered !?
5
2584
by: Gianni Mariani | last post by:
I'm hoping someone can tell me why using member address of works and why using the dot operator does not in the code below. The code below uses the template function resolution mechanism to determine wether a class contains a member. My understanding is that if a template function has an error during resolution of the function types, it is quietly eliminated from the resolution process. This can be used to detect things that would...
7
2456
by: sidewinder | last post by:
I wish to use a C++ vector class, which I have taken from the book numerical recipes. However due to the nature of the calculations I wish to perform I need to be able to delete the vectors. I thought that the line ~VEC<double>(a); would do this however when trying to compile using g++ I get the error "no match for ‘operator~’ in ‘~VEC<double>(((const VEC<double>&)((const VEC<double>*)(& a))))" I am sorry this is a bit of a newbie question,...
2
3152
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
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
8341
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
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
8630
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
7362
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
4177
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
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
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.