Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > still confused about headers, inline functions, linking, and redefining

Reply
Thread Tools

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

 
 
pookiebearbottom@yahoo.com
Guest
Posts: n/a
 
      07-18-2006
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

 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Pedro_Lamar=E3o?=
Guest
Posts: n/a
 
      07-18-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) 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; }

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      07-18-2006
(E-Mail Removed) 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.
 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      07-18-2006
Pedro Lamarão wrote:

> (E-Mail Removed) 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.
 
Reply With Quote
 
pookiebearbottom@yahoo.com
Guest
Posts: n/a
 
      07-18-2006
Pete Becker wrote:
> Pedro Lamarão wrote:
>
> > (E-Mail Removed) 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"?

 
Reply With Quote
 
Artie Gold
Guest
Posts: n/a
 
      07-18-2006
(E-Mail Removed) wrote:
> Pete Becker wrote:
>
>>Pedro Lamarão wrote:
>>
>>
>>>(E-Mail Removed) 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.]
 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      07-18-2006
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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple functions (one version being inline and other beingnon-inline) Rahul C++ 3 02-28-2008 03:28 PM
about extern inline and static inline Sean C++ 4 04-30-2006 03:18 PM
redefining, and casting pointers to, structs goldfita@signalsguru.net C Programming 17 01-11-2006 06:01 AM
Inline classes and template templates... confused Mark C++ 2 09-18-2004 03:04 AM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments