You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`__inline`** keyword tells the compiler to substitute the code within the function definition for every instance of a function call.
10
+
The **`inline`** keyword is a function specifier that tells the compiler to substitute the code within the function definition for every instance of a function call.
13
11
14
12
## Remarks
15
13
@@ -19,7 +17,7 @@ For a function to be considered as a candidate for inlining, it must use the new
19
17
20
18
Use this form to specify an inline function:
21
19
22
-
> **`__inline`***function-definition*
20
+
> **`inline`***function-definition*
23
21
24
22
Inline functions generate faster and sometimes smaller code than the equivalent function call:
25
23
@@ -29,7 +27,13 @@ Inline functions generate faster and sometimes smaller code than the equivalent
29
27
30
28
- The compiler can optimize functions generated inline in ways that aren't available to normal functions. The compiler doesn't usually perform optimizations between different procedures.
31
29
32
-
Don't confuse functions that use **`__inline`** with inline assembler code. For more information about inline assembler, see [Inline assembler](../c-language/inline-assembler-c.md).
30
+
Don't confuse functions that use **`inline`** with inline assembler code. For more information about inline assembler, see [Inline assembler](../c-language/inline-assembler-c.md).
31
+
32
+
**Microsoft specific**
33
+
34
+
Microsoft also supports **`__inline`** and **`__forceinline`** keywords to tell the compiler to substitute the code within the function definition for every instance of a function call. The **`__inline`** keyword is a synonym for **`inline`**. The **`__forceinline`** keyword tells the compiler to relax the heuristics on whether to inline the function, though it doesn't guarantee a function will be inlined.
35
+
36
+
For compatibility with previous versions, **`_inline`** and **`_forceinline`** are synonyms for **`__inline`** and **`__forceinline`**, respectively, unless compiler option [`/Za`\(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) is specified.
helpviewer_keywords: ["inline functions [C++], class members"]
7
7
ms.assetid: 355f120c-2847-4608-ac04-8dda18ffe10c
@@ -57,7 +57,7 @@ int main()
57
57
58
58
A given inline member function must be declared the same way in every compilation unit. This constraint causes inline functions to behave as if they were instantiated functions. Additionally, there must be exactly one definition of an inline function.
59
59
60
-
A class member function defaults to external linkage unless a definition for that function contains the **`inline`** specifier. The preceding example shows that you don't have to declare these functions explicitly with the **`inline`** specifier. Using **`inline`** in the function definition causes it to be an inline function. However, it's not allowed to redeclare a function as **`inline`** after a call to that function.
60
+
A class member function defaults to external linkage unless a definition for that function contains the **`inline`** specifier. The preceding example shows that you don't have to declare these functions explicitly with the **`inline`** specifier. Using **`inline`** in the function definition causes it to be an inline function. However, you can't redeclare a function as **`inline`** after a call to that function.
61
61
62
62
## `inline`, `__inline`, and `__forceinline`
63
63
@@ -67,9 +67,9 @@ The insertion, called *inline expansion* or *inlining*, occurs only if the compi
67
67
68
68
The **`__forceinline`** keyword overrides the cost-benefit analysis and relies on the judgment of the programmer instead. Exercise caution when using **`__forceinline`**. Indiscriminate use of **`__forceinline`** can result in larger code with only marginal performance gains or, in some cases, even performance losses (because of the increased paging of a larger executable, for example).
69
69
70
-
The compiler treats the inline expansion options and keywords as suggestions. There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the **`__forceinline`** keyword. When compiling with **`/clr`**, the compiler won't inline a function if there are security attributes applied to the function.
70
+
The compiler treats the inline expansion options and keywords as suggestions. There's no guarantee that functions will be inlined. You can't force the compiler to inline a particular function, even with the **`__forceinline`** keyword. When you compile with **`/clr`**, the compiler won't inline a function if there are security attributes applied to the function.
71
71
72
-
The **`inline`** keyword is available only in C++. The **`__inline`** and **`__forceinline`** keywords are available in both C and C++. For compatibility with previous versions, **`_inline`** and **`_forceinline`** are synonyms for **`__inline`**, and **`__forceinline`** unless compiler option [`/Za` \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) is specified.
72
+
For compatibility with previous versions, **`_inline`** and **`_forceinline`** are synonyms for **`__inline`** and **`__forceinline`**, respectively, unless compiler option [`/Za` \(Disable language extensions)](../build/reference/za-ze-disable-language-extensions.md) is specified.
73
73
74
74
The **`inline`** keyword tells the compiler that inline expansion is preferred. However, the compiler can create a separate instance of the function (instantiate) and create standard calling linkages instead of inserting the code inline. Two cases where this behavior can happen are:
0 commit comments