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 syntax of function-like macros is similar to the syntax of a function call.
77
+
They accept a list of arguments and replace their occurrence in the
78
+
replacement-list.
79
+
80
+
As this is only a text replacement, it can lead to unexpected behaviour if the
81
+
arguments are not properly separated with brackets.
82
+
83
+
In function-like macros, the operators `#` and `##` enable:
84
+
85
+
-`#operator (stringification)` - the arguments of the macro are converted to
86
+
a string literal without expanding the argument. When `#` is used in front
87
+
of a parameter in a macro definition (`#param`), the preprocessor replaces
88
+
`#param` with the argument tokens as a string literal.
89
+
90
+
-`##operator (concatenation or token pasting)` - two tokens are merged in a
91
+
single token during a macro expansion. For example, when `a##b` is used as
92
+
part of the macro definition, the preprocessor merges `a` and `b`, removing
93
+
any white spaces in between to form a single token. When some of the tokens
94
+
on either side of the `##` operator are parameter names, they are replaced
95
+
by the actual argument before the execution of `##`. This is used for
96
+
example to create new identifiers like variables, function names etc. and in
97
+
general to avoid creating repeated boilerplate code.
98
+
99
+
#### Predefined macros
100
+
101
+
There are also predefined macros available in every translation unit. Examples
102
+
include: `__cplusplus`, `__FILE__`, `__LINE__`, `__DATE__`, `__TIME__` etc.
103
+
104
+
### Swift / C interop [[GitHub](https://github.com/swiftlang/swift/blob/main/lib/ClangImporter/ImportMacro.cpp)][[documentation](https://developer.apple.com/documentation/swift/using-imported-c-macros-in-swift)]
105
+
106
+
Swift supports importing object-like C macros as global constants. Macros that
107
+
use integer, floating-point and string literals are supported. Also simple
108
+
operators like `+, -, <<, >>` etc. between literals or macros are supported.
109
+
110
+
Function-like macros are not supported. Instead, using Swift functions and
0 commit comments