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
Copy file name to clipboardExpand all lines: docs/cpp/inline-functions-cpp.md
-56Lines changed: 0 additions & 56 deletions
Original file line number
Diff line number
Diff line change
@@ -202,62 +202,6 @@ Assuming coordinate manipulation is a relatively common operation in a client of
202
202
203
203
- Return
204
204
205
-
## Inline functions vs. macros
206
-
207
-
Inline functions are similar to macros, because the function code is expanded at the point of the call at compile time. However, inline functions are parsed by the compiler, and macros are expanded by the preprocessor. As a result, there are several important differences:
208
-
209
-
- Inline functions follow all the protocols of type safety enforced on normal functions.
210
-
211
-
- Inline functions are specified using the same syntax as any other function except that they include the **`inline`** keyword in the function declaration.
212
-
213
-
- Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.
214
-
215
-
The following example shows a macro that converts lowercase letters to uppercase:
The intent of the expression `toupper(getc(stdin))` is that a character should be read from the console device (`stdin`) and, if necessary, converted to uppercase.
235
-
236
-
Because of the implementation of the macro, `getc` is executed once to determine whether the character is greater than or equal to "a," and once to determine whether it's less than or equal to "z." If it is in that range, `getc` is executed again to convert the character to uppercase. It means the program waits for two or three characters when, ideally, it should wait for only one.
237
-
238
-
Inline functions remedy the problem previously described:
239
-
240
-
```cpp
241
-
// inline_functions_inline.cpp
242
-
#include<stdio.h>
243
-
#include<conio.h>
244
-
245
-
inlinechartoupper( char a ) {
246
-
return ((a >= 'a' && a <= 'z') ? a-('a'-'A') : a );
0 commit comments