Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Inline function
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Function in the C and C++ programming languages}} {{About|inline functions in C and C++|inline expansion more generally|Inline expansion}} {{distinguish|Inline assembler}} <noinclude>{{Requested move notice|1=Inline (C and C++)|2=Talk:Inline function#Requested move 27 May 2025}} </noinclude> {{Update|reason=Meaning of inline changed in C++ (https://en.cppreference.com/w/cpp/language/inline)|date=April 2019}} In the [[C (programming language)|C]] and [[C++]] [[programming language]]s, an '''inline function''' is one qualified with the [[Keyword (computer programming)|keyword]] <code>inline</code>; this serves two purposes: # It serves as a [[compiler directive]] that suggests (but does not require) that the [[compiler]] substitute the body of the function inline by performing [[inline expansion]], i.e. by inserting the function code at the address of each function call, thereby saving the overhead of a function call. In this respect it is analogous to the <code>register</code> [[storage class specifier]], which similarly provides an optimization hint.<ref name="meyers2002">{{cite journal |title=The New C: Inline Functions |url=http://www.drdobbs.com/the-new-c-inline-functions/184401540 |first=Randy |last=Meyers |date=July 1, 2002}}</ref> # The second purpose of <code>inline</code> is to change linkage behavior; the details of this are complicated. This is necessary due to the C/C++ separate compilation + linkage model, specifically because the definition (body) of the function must be duplicated in all [[Translation unit (programming)|translation unit]]s where it is used, to allow inlining during ''compiling'', which, if the function has external [[Linkage (software)|linkage]], causes a collision during ''linking'' (it violates uniqueness of external symbols). C and C++ (and dialects such as GNU C and Visual C++) resolve this in different ways.<ref name="meyers2002"/>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)