Function inlining

I

Ian

This is partly related to the kernel C/C++ thread, one thing I'm not
sure about with modern C compiler is how aggressively they inline
trivial functions as an optimisation.

A C++ compiler will be fairly aggressive in this area, so it is
generally safe to assume that short functions will get inlined away as
this tends to improve both code size and execution speed.

Do modern C compilers do the same?

Cheers,

Ian.
 
M

Mark McIntyre

On Sun, 15 Jan 2006 10:07:50 +1300, in comp.lang.c , Ian

(of optimisation)
Do modern C compilers do the same?

This is not topical here, since it depends on the compiler not on the
language. For an authorative answer you'd need to ask in groups
specialising in various compilers. Offhand however I'd simply point
out that most compiler suites these days contain C and C++ tools from
the same source and it'd be pretty bizarre not to perform similar
optimizations in your two offerings.
Mark McIntyre
 
J

Jack Klein

This is partly related to the kernel C/C++ thread, one thing I'm not
sure about with modern C compiler is how aggressively they inline
trivial functions as an optimisation.

A C++ compiler will be fairly aggressive in this area, so it is
generally safe to assume that short functions will get inlined away as
this tends to improve both code size and execution speed.

Do modern C compilers do the same?

First, please use a proper signature delimiter, like mine at the
bottom. It consists of "-- ". Most newsreaders recognize this and
provide proper handling automatically.

Second, what is your definition of "modern C compilers"? Optimization
is both inherently implementation specific, and not defined by the C
standard. If you want to know about the behavior of specific
compilers, as in their compiler specific support groups or try them
yourself.

Note that compilers that support the 1999 or later versions of the C
standard recognize the inline keyword to specifically suggest to the
compiler that you want a particular function inlined. Just as with
the register keyword, the compiler is free to ignore your request.
 
I

Ian Collins

Jack said:
First, please use a proper signature delimiter, like mine at the
bottom. It consists of "-- ". Most newsreaders recognize this and
provide proper handling automatically.
OK, done.
Second, what is your definition of "modern C compilers"? Optimization
is both inherently implementation specific, and not defined by the C
standard. If you want to know about the behavior of specific
compilers, as in their compiler specific support groups or try them
yourself.

Note that compilers that support the 1999 or later versions of the C
standard recognize the inline keyword to specifically suggest to the
compiler that you want a particular function inlined. Just as with
the register keyword, the compiler is free to ignore your request.
It's been a while since I've studied compiler output on embedded
systems, but when I was working in this area, we had to resort to macros
rather than short functions because our compiler didn't inline trivial
functions.

I was simply curious about the current state of the art.
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top