473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 1922
> 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
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"...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
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...
18
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
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....
5
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...
7
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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
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,...
0
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...

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.