C Inlining

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

What is C inlinging? Or inlining. Does it have something to do with using C
and assembly language together? I know some of the linux kernel is inlined
and it's written in C with a little assembly.

Bill
 
J

Jens.Toerring

Bill Cunningham said:
What is C inlinging? Or inlining. Does it have something to do with using C
and assembly language together? I know some of the linux kernel is inlined
and it's written in C with a little assembly.

Inlining means that a function declared as 'inline' (which has become
an offical C feature only with C99 but was supported by many compilers
before as an extension) will not be really created but instead the code
for the function is placed everywhere where the function is called.
Lets say you have an inlined function my_abs():

inline double my_abs( double val )
{
return val >= 0 ? val : - val;
}

and you call it as

x = my_abs( y );

then the compiler won't create a call to the function but instead will
replace it with the functions code, resulting in something similar to

x = y >= 0 ? y : - y;

This can increase execution speed a bit because the overhead for calling
a function is eliminated.
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| (e-mail address removed)-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
 
T

Tristan Miller

Greetings.

What is C inlinging? Or inlining. Does it have something to do with using
C and assembly language together? I know some of the linux kernel is
inlined and it's written in C with a little assembly.

The term 'inlining' can have different meanings. In standard C, it refers
to declaring a function with the 'inline' keyword, which is a suggestion to
the compiler that it insert the function's code verbatim wherever it is
called, rather than only producing the code for the function once and
calling it as a subroutine. Obviously there's a time-space tradeoff
involved.

The meaning of 'inline' you refer to deals with inserting code from another
programming language, such as SQL or assembly, into a C program. Support
for this type of inlining is compiler-specific; ISO/ANSI C does not provide
for a standard method. If you want to know how to inline assembly in C or
have questions about the Linux kernel, you need to ask on a Linux- or
compiler-specific newsgroup.

Regards,
Tristan
 
M

Malcolm

Bill Cunningham said:
What is C inlinging? Or inlining. Does it have something to do with
using C and assembly language together? I know some of the linux
kernel is inlined and it's written in C with a little assembly.
Most compilers allow you to add assembly statements to C code, typically
using "asm" as a keyword.
Needless to say, the details are very platform-specific, and such code is
not portable.
 
P

Peter Pichler

Malcolm said:
Most compilers allow you to add assembly statements to C code, typically
using "asm" as a keyword.
Needless to say, the details are very platform-specific, and such code is
not portable.

OTOH, inlining may have nothing to do with asm. The C99 keyword inline,
supported by many pre-C99 compilers as a common extension, means basically
that the function body is expanded whenever the function declared as
inline is called. This saves a function call overhead and allows for
better optimization, but tends to bloat the code if the inline function
is used in more than one place.

Sorry if this has been mentioned in the thread already, I have joined only
now and have not seen any other reply than Malcolm's.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top