niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » C++
still confused about headers, inline functions, linking, and redefining
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
pookiebearbottom@yahoo.co
*nix forums beginner


Joined: 19 Dec 2005
Posts: 3

PostPosted: Tue Jul 18, 2006 3:58 pm    Post subject: still confused about headers, inline functions, linking, and redefining Reply with quote

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
Back to top
thoth39
*nix forums beginner


Joined: 26 May 2005
Posts: 3

PostPosted: Tue Jul 18, 2006 4:15 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

pookiebearbottom@yahoo.com wrote:
Quote:
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; }
Back to top
Pete Becker
*nix forums Guru


Joined: 22 Feb 2005
Posts: 682

PostPosted: Tue Jul 18, 2006 5:09 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

pookiebearbottom@yahoo.com wrote:
Quote:
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.
Back to top
Pete Becker
*nix forums Guru


Joined: 22 Feb 2005
Posts: 682

PostPosted: Tue Jul 18, 2006 5:10 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

Pedro Lamarão wrote:

Quote:
pookiebearbottom@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.
Back to top
pookiebearbottom@yahoo.co
*nix forums beginner


Joined: 19 Dec 2005
Posts: 3

PostPosted: Tue Jul 18, 2006 5:18 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

Pete Becker wrote:
Quote:
Pedro Lamarão wrote:

pookiebearbottom@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"?
Back to top
Artie Gold
*nix forums Guru


Joined: 06 Apr 2005
Posts: 327

PostPosted: Tue Jul 18, 2006 5:31 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

pookiebearbottom@yahoo.com wrote:
Quote:
Pete Becker wrote:

Pedro Lamarão wrote:


pookiebearbottom@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.]
Back to top
Ron Natalie
*nix forums Guru


Joined: 21 Feb 2005
Posts: 461

PostPosted: Tue Jul 18, 2006 5:55 pm    Post subject: Re: still confused about headers, inline functions, linking, and redefining Reply with quote

Artie Gold wrote:

Quote:

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).
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:35 am | All times are GMT
navigation Forum index » Programming » C++
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts squid 2.6STABLE1 strips authentication headers Anton Golubev Squid 0 Thu Jul 20, 2006 9:43 pm
No new posts template vs. ordinary functions how it is overloaded dalu.gelu@gmail.com C++ 4 Thu Jul 20, 2006 6:59 am
No new posts Depricated String Functions in Python Anoop python 14 Thu Jul 20, 2006 6:26 am
No new posts How to recognise "generator functions" ? imho python 2 Wed Jul 19, 2006 10:01 pm
No new posts Linking Tables from 2 databases Pratik Shukla PostgreSQL 2 Wed Jul 19, 2006 5:54 pm

Loans | Watch Naruto Online | Bankruptcy | Personal Loans | Photography
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1575s ][ Queries: 16 (0.0715s) ][ GZIP on - Debug on ]