[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inline functions with gnu99
From: |
Ben Pfaff |
Subject: |
Re: inline functions with gnu99 |
Date: |
Sun, 23 Mar 2008 17:54:33 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
John Darrington <address@hidden> writes:
> Interesting. I never knew there was more than one interpretation.
>
> To me, the inline keyword is a hint to the compiler that it might be
> better to replace any calls to the function concerned with the body of
> the function, rather than making a subroutine.
>
> What else might it mean?
That is always what "inline" means at the highest level. But GCC
and C99 "inline" have different linkage semantics. Here is some
information on the difference:
http://gcc.gnu.org/ml/gcc/2006-11/msg00006.html
Here is an excerpt from the GCC 4.3 manual, in the node titled
"Inline", that talks about the static inline case:
GCC implements three different semantics of declaring a function
inline. One is available with `-std=gnu89' or `-fgnu89-inline' or when
`gnu_inline' attribute is present on all inline declarations, another
when `-std=c99' or `-std=gnu99' (without `-fgnu89-inline'), and the
third is used when compiling C++.
[...]
The three types of inlining behave similarly in two important cases:
when the `inline' keyword is used on a `static' function, like the
example above, and when a function is first declared without using the
`inline' keyword and then is defined with `inline', like this:
extern int inc (int *a);
inline int
inc (int *a)
{
(*a)++;
}
In both of these common cases, the program behaves the same as if you
had not used the `inline' keyword, except for its speed.
--
Ben Pfaff
http://benpfaff.org