|
|
|
|
|
|
| Author |
Message |
pookiebearbottom@yahoo.co *nix forums beginner
Joined: 19 Dec 2005
Posts: 3
|
Posted: Tue Jul 18, 2006 3:58 pm Post subject:
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 |
|
| Back to top |
|
 |
thoth39 *nix forums beginner
Joined: 26 May 2005
Posts: 3
|
Posted: Tue Jul 18, 2006 4:15 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:09 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:10 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:18 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:31 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:55 pm Post subject:
Re: still confused about headers, inline functions, linking, and redefining
|
|
|
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 |
|
 |
|
|
The time now is Thu Jan 08, 2009 6:35 am | All times are GMT
|
|
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
|
|