473,383 Members | 1,984 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,383 software developers and data experts.

still confused about headers, inline functions, linking, and redefining

Let's say I have headers Sal.h with this class

class Sal
{
public:
int doit() { return 1;}
};

now I know that the compilier can choose NOT to inline this function.
So if I include this in two different libraries, they both choose to
NOT inline it, and then I link to both libs, am I going to get/should I
get a redefinition error?

-sal

Jul 18 '06 #1
6 2860

po**************@yahoo.com wrote:
Let's say I have headers Sal.h with this class

class Sal
{
public:
int doit() { return 1;}
};

now I know that the compilier can choose NOT to inline this function.
So if I include this in two different libraries, they both choose to
NOT inline it, and then I link to both libs, am I going to get/should I
get a redefinition error?
You will get a redefinition error.

Say both library A and library B have a source file including this
header. This means that, say, a.cpp and b.cpp, after preprocessing,
will include the code above -- the declaration for class Sal and the
definition for Sal::doit.

If you link these libraries together, the linker will simply see two
definitions for the same name, and issue an error.

If you really want to, you can use "extern inline" to provide a
definition only for inlining -- and then provide another definition
somewhere, probably in a source file for the library, when the compiler
decides not to inline the call.

Something like this:

Sal.h:

class Sal
{
public:

extern inline
int doit() { return 1; }
};

Sal.cpp:

int Sal::doit() { return 1; }

Jul 18 '06 #2
po**************@yahoo.com wrote:
Let's say I have headers Sal.h with this class

class Sal
{
public:
int doit() { return 1;}
};

now I know that the compilier can choose NOT to inline this function.
So if I include this in two different libraries, they both choose to
NOT inline it, and then I link to both libs, am I going to get/should I
get a redefinition error?
No. The compiler will handle it.
Jul 18 '06 #3
Pedro Lamarão wrote:
po**************@yahoo.com wrote:
>>Let's say I have headers Sal.h with this class

class Sal
{
public:
int doit() { return 1;}
};

now I know that the compilier can choose NOT to inline this function.
So if I include this in two different libraries, they both choose to
NOT inline it, and then I link to both libs, am I going to get/should I
get a redefinition error?


You will get a redefinition error.
No, the compiler will handle it.
Jul 18 '06 #4
Pete Becker wrote:
Pedro Lamarão wrote:
po**************@yahoo.com wrote:
>Let's say I have headers Sal.h with this class
You will get a redefinition error.

No, the compiler will handle it.
This is why I get confused. Wouldn't it be a linker issue anyway? Is
this covered by any "standard"?

Jul 18 '06 #5
po**************@yahoo.com wrote:
Pete Becker wrote:
>>Pedro Lamarão wrote:

>>>po**************@yahoo.com wrote:
Let's say I have headers Sal.h with this class
You will get a redefinition error.

No, the compiler will handle it.


This is why I get confused. Wouldn't it be a linker issue anyway? Is
this covered by any "standard"?
It is covered by the C++ standard.

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Jul 18 '06 #6
Artie Gold wrote:
>>
This is why I get confused. Wouldn't it be a linker issue anyway? Is
this covered by any "standard"?
It is covered by the C++ standard.
Yes, the standard says that duplicates of inline functions are allowed
as long as they are the same sequence of tokens in the function definition.

This is actually the only practical difference inline does. Whether
the declaration does anything else is an implementation detail (a
implementation is free to not inline inline functions or to inline
those not declared inline).
Jul 18 '06 #7

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

Similar topics

14
by: Chris Mantoulidis | last post by:
I am not clear with the use of the keyword inline... I believe you add it do a function when you implement the function inside the header file where the class is stored... But is that all? What...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
8
by: Sreenivas | last post by:
Hi, We cannot return a reference to an automatic variable from a function, as per the ANSI C++ standard the behaviour is undefined. Does this hold for inline functions too? or can I return a...
7
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must...
6
by: John Ratliff | last post by:
I was reading the C++ FAQ Lite about inline functions, and it says the following (http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7) " It's usually imperative that the...
9
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...
5
by: ciccio | last post by:
Hi, I have a problem with my code that the compiler does not find any inline functions which are static. The simple code example is written below, this is what the compiler throws at me. ]...
1
by: arjor | last post by:
hey guys When i try to make the following mutating method inline i get the following error: //method inline void vertex::setValue(int new_value) throw() { value_ = new_value; } error...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.