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 6 2913 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; } 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.
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.
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"? 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.]
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). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 am I missing?
If that's all, then why did Bjarne even bother adding it to the
language?
If that's not all, what else can I do with "inline"?
|
by: Richard Hayden |
last post by:
Hi,
I have the following code:
/******************************** file1.c
#include <iostream>
extern void dummy();
inline int testfunc() {
|
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 reference to the automatic variable from the
inline function. I meant automatic variable by stack variable strictly local to
that function.
Thanks,
Sreenivas.
|
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 be defined either within
the class or within the same header file.
But its generally a good programming practice to have the declarations
and definitions in seperate files. This would make the future
maintenance of the code easier.
|
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 function's definition (the part between
the {...}) be placed in a header file. If you put the inline function's
definition into a .cpp file, and if it is called from some other .cpp file,
you'll get an "unresolved external" error from the linker. "
Why...
| |
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 would expect to see
it inlined during linkage of the two object files. Does inlining only
occur if the inline function is defined within the same file that it is
called?
Thanks,
|
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.
] $ g++ main.cpp foo.cpp
/home/klaas/tmp/cciAcYgl.o: In function `main':
|
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 LNK2019: unresolved external symbol "public: void __thiscall
vertex::setValue(int)" (?setValue@vertex@@QAEXH@Z) referenced in
|
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 the
function if possible" (because if the compiler has the function
definition available at an instantiation point, it will estimate whether
to inline it or not, and do so if it estimates it would be beneficial,
completely regardless of whether...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |