473,385 Members | 2,005 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,385 software developers and data experts.

exporting inline functions

Hi,

My observation was that a function with `inline' qualifier has file
scope in C++ and it's symbol is not exported. Contrary to this, in C an
`inline' function symbol is exported, unless it also has `static' or
`extern' qualifiers.

How could I achieve the C behaviour in C++, in that an inline function
symbol is exported? I see that one way to do it is declaring the
function in a class definition in a header file so that all files
including it get the copy of the function. Is there no way to share in
the symbol level? I think it is useful because one may want to have a
library of functions that are used inline, whenever they're referenced.

Thanks,
Bahadir

Mar 2 '06 #1
3 6449
* Bi*************@gmail.com:

My observation was that a function with `inline' qualifier has file
scope in C++ and it's symbol is not exported.
Presumably by "file scope" you mean internal linkage, and by "not
exported" you mean internal linkage.

No, it's not that way.

Contrary to this, in C an
`inline' function symbol is exported, unless it also has `static' or
`extern' qualifiers.
I think you got this one wrong too.

How could I achieve the C behaviour in C++, in that an inline function
symbol is exported? I see that one way to do it is declaring the
function in a class definition in a header file so that all files
including it get the copy of the function. Is there no way to share in
the symbol level? I think it is useful because one may want to have a
library of functions that are used inline, whenever they're referenced.


An external linkage "inline" function must be defined (identically) in
every translation it's used. The "inline" qualifier informs the
compiler and linker that all definitions are the same. Hence the linker
can choose any single one, and you don't get a multiple def error.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 2 '06 #2
Alf P. Steinbach wrote:
* Bi*************@gmail.com:

My observation was that a function with `inline' qualifier has file
scope in C++ and it's symbol is not exported.
Presumably by "file scope" you mean internal linkage, and by "not
exported" you mean internal linkage.


Yes you're right on this, after posting I realised `file scope' isn't
what I was trying to say.
Contrary to this, in C an
`inline' function symbol is exported, unless it also has `static' or
`extern' qualifiers.
I think you got this one wrong too.

An external linkage "inline" function must be defined (identically) in
every translation it's used. The "inline" qualifier informs the
compiler and linker that all definitions are the same. Hence the linker
can choose any single one, and you don't get a multiple def error.


By external linkage inline I guess you mean a declaration like:
extern inline void function(void) { }

I have seen the same description (i.e. picking up any definition) as
yours in gcc documentation and it makes sense.

Getting back to my original argument however, using gcc and producing
an object file in C, I have observed that no symbol was exported
(internal linkage) for a function declared "extern inline". This makes
me think, does the compiler avoid multiple def errors by not exporting
the symbol in the object file produced? My expectation would be to have
multiple definitions of same symbol in many object files and the linker
would resolve it by picking only one of them, because they're marked as
external linkage, in the object file level. Incorrect?

If we get back to just "inline" declaration, C compilation did export
the symbol in the object file produced.* However in C++, merely
declaring a function `inline' only, I had no exported symbols from the
file. Do you think this is how it's supposed to be?

Many thanks,
Bahadir

*I am using something like gcc -c file.c to produce the object file.

Mar 2 '06 #3
* Bi*************@gmail.com:
Alf P. Steinbach wrote:
* Bi*************@gmail.com:
My observation was that a function with `inline' qualifier has file
scope in C++ and it's symbol is not exported. Presumably by "file scope" you mean internal linkage, and by "not
exported" you mean internal linkage.


Yes you're right on this, after posting I realised `file scope' isn't
what I was trying to say.
Contrary to this, in C an
`inline' function symbol is exported, unless it also has `static' or
`extern' qualifiers.

I think you got this one wrong too.

An external linkage "inline" function must be defined (identically) in
every translation it's used. The "inline" qualifier informs the
compiler and linker that all definitions are the same. Hence the linker
can choose any single one, and you don't get a multiple def error.


By external linkage inline I guess you mean a declaration like:
extern inline void function(void) { }


Just

inline void function() {}

means the same.

I have seen the same description (i.e. picking up any definition) as
yours in gcc documentation and it makes sense.

Getting back to my original argument however, using gcc and producing
an object file in C, I have observed that no symbol was exported
(internal linkage) for a function declared "extern inline".
The compiler doesn't need to place the symbol in the object code, it's
just allowed to do that.

Especially if this is a small function that's naturally machine-code
inlined everywhere, and you don't take its address, there's no separate
function around after compilation.

Then it would just be more work for the linker if the compiler emitted
the function symbol.

This makes
me think, does the compiler avoid multiple def errors by not exporting
the symbol in the object file produced?
It might, but I don't think so.

Anyway the standard does not go into how a compiler should achieve the
required effect.

It does not even acknowledge the existence of compilers... ;-)

My expectation would be to have
multiple definitions of same symbol in many object files and the linker
would resolve it by picking only one of them, because they're marked as
external linkage, in the object file level. Incorrect?
Try taking the address the of the function and passing it around. Then
the function has to exist, and the compiler needs to ensure that you
have the same address as will be obtained in any other translation unit.
Hence it "must" (with a reasonable way of doing things) emit the
function symbol in the object code.

If we get back to just "inline" declaration, C compilation did export
the symbol in the object file produced.* However in C++, merely
declaring a function `inline' only, I had no exported symbols from the
file. Do you think this is how it's supposed to be?


See above; when the compiler can get away with it, it's free to do so.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 2 '06 #4

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

Similar topics

13
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg....
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() {
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
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...
4
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at...
43
by: Patrick Laurent | last post by:
Hello I have a program with many many inlined template functions It is essential for the execution speed that every (or almost every) function marked as inlined, becomes really inlined by the...
0
by: victorsk | last post by:
Hello, I need to write a DLL app in VB whose functions would be called by another app. VB's DLL's don't support exporting functions. However, I found a site that provides a way to export VB...
2
by: Mux | last post by:
I am facing the following problem while exporting data to Word. The current implementation is as described below: I have a JSP file which has a link that enables you to export the data to Word....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...

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.