473,385 Members | 1,329 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.

How to inline non-exported functions in library?

Ian
Peace, language lawyers!

I'm developing a (static) library for a "memory-challenged"
platform (ie, mobile).

I want to (force the compiler to) inline some functions -- that
are not meant to be exported to the library's clients.

Example:

file1.c:
// Exported.
public_foo( void ); // Calls my_bar() and common_bar().

// Private.
static INLINE my_bar( void ); // Only called by functions in
this translation unit.
INLINE common_bar( void ); // May be called from other
translation units, too.

file2.c:
// Exported.
public_another_foo( void ); // Calls common_bar().

Currently, to inline and prevent exporting, I #include a file with
the static INLINE function.

This is not _standard_ C, but most compilers do provide some
"inline" keyword as a language extension.

Questions:

1. Is there a readable, manageable, semi-portable way to inline
functions in a library?

2. Your experience with compilers (especially GCC, VC, ARM's,
TI's): will they allow inlining, especially of non-static
functions, when building a library?

:o)

--
Ian

Nov 15 '05 #1
3 2769
Ian <ha**@spam.com> wrote:
I want to (force the compiler to) inline some functions -- that
are not meant to be exported to the library's clients.

Example:

file1.c:
// Exported.
public_foo( void ); // Calls my_bar() and common_bar().

// Private.
static INLINE my_bar( void ); // Only called by functions in
this translation unit.
INLINE common_bar( void ); // May be called from other Currently, to inline and prevent exporting, I #include a file with
the static INLINE function.

This is not _standard_ C, but most compilers do provide some
"inline" keyword as a language extension.

Questions:

1. Is there a readable, manageable, semi-portable way to inline
functions in a library?


C99 provides the inline keyword. As you note, quite a few C89 compilers
do so as an extension, too. Apart from that, I don't know any way.

Richard
Nov 15 '05 #2
Ian wrote:
I'm developing a (static) library for a "memory-challenged"
platform (ie, mobile).

I want to (force the compiler to) inline some functions -- that
are not meant to be exported to the library's clients.

Currently, to inline and prevent exporting, I #include a file with
the static INLINE function.

This is not _standard_ C, but most compilers do provide some
"inline" keyword as a language extension.

Questions:

1. Is there a readable, manageable, semi-portable way to inline
functions in a library?
There are some other ways of doing this. You could remove the names from
your final object (using the strip command) or only include names that
you want to be included (see option --retain-symbols-file of the Gnu
linker). I don't know if this option is available for other linkers.
As you are working on a "memory challenged" device I think this would be
preferable over inline, as inline will include your code multiple times
in your final object.

Another way might be to use static functions instead of inline. This
might take some redesign, as you can only use static functions in the
scope of a module, but it would also get you the same result. The result
will be portable and will not rely on the use of the (non-standard for
pre-C99) inline keyword.

Kind regards,
Johan

--
o o o o o o o . . . _____J_o_h_a_n___B_o_r_k_h_u_i_s___
o _____ || http://www.borkhuis.com |
.][__n_n_|DD[ ====_____ | jo***@borkhuis.com |(________|__|_[_________]_|________________________________|

_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
== VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
Nov 15 '05 #3

Richard Bos wrote:
Ian <ha**@spam.com> wrote:
I want to (force the compiler to) inline some functions -- that
are not meant to be exported to the library's clients.

Example:

file1.c:
// Exported.
public_foo( void ); // Calls my_bar() and common_bar().

// Private.
static INLINE my_bar( void ); // Only called by functions in
this translation unit.
INLINE common_bar( void ); // May be called from other
Currently, to inline and prevent exporting, I #include a file with
the static INLINE function.

This is not _standard_ C, but most compilers do provide some
"inline" keyword as a language extension.

Questions:

1. Is there a readable, manageable, semi-portable way to inline
functions in a library?


C99 provides the inline keyword.


... and, a word of caution.

Semantics
[...] Making a function an inline function suggests that calls to
the function be as fast as possible. The extent to which such
suggestions are effective is implementation-defined.
As you note, quite a few C89 compilers
do so as an extension, too. Apart from that, I don't know any way.


Nov 15 '05 #4

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

Similar topics

2
by: qazmlp | last post by:
// test.h class test { public : inline void check() ; } ; // test.C inline void test::check() // Is 'inline' optional here?
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...
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
25
by: Brian Lindahl | last post by:
I'm using a temporary buffer to transfer some data and would rather not allocate it on the heap. The problem is that the size of the buffer is only known upon entry into the function that utilizes...
6
by: Sharon | last post by:
Usually it is common to write the class member function in the class H file, but some people like to write the function body in the C++ file. Can anybody tell me what are the cases where inline...
6
by: Anders M | last post by:
I'm trying to use Inline-code to call Page_load, Page_Init or Page_PreRender methods. I've also got a code behind c#-file. I can define inline methods for buttons and so on...that works fine....
3
by: shuisheng | last post by:
Dear All, If I define a virtual function to be inline, is it really inline? Or it is inline in some cases, and not in other cases. Would you please help me to look at the following case. ...
14
by: jg | last post by:
Does C++ standard require an inline function be generated all the time ? For example, #include <iostream> using namespace std; inline int foo() {
0
by: Shadow Lynx | last post by:
Could someone sum up the difference(s) between the standard CSS display: inline block and the non-standard Firefox (Mozilla) display: - moz-inline-box? I have used the following in a couple of...
12
by: subramanian100in | last post by:
Can a ctor be declared inline ? Is it not declared inline to avoid executable code size becoming huge ? kindly clarify Thanks V.Subramanian
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.