Contents
Can a macro have more than one argument?
Multiple arguments You can have multiple arguments to a macro, e.g. The usual caveats about using lots of parentheses apply. 1.2. Perils of repeating arguments Macros can have odd effects if their arguments perform side-effects.
What are some examples of macros having odd effects?
Macros can have odd effects if their arguments perform side-effects. For example, Square (++x) expands to ( (++x)* (++x)); if x starts out equal to 1, this expression may evaluate to any of 2, 6, or 9 depending on when the ++ operators are evaluated, and will definitely leave 3 in x instead of the 2 the programmer probably expects.
How to use multiple expressions in a macro?
Multiple expressions in a macro Use the comma operator, e.g. The comma operator evaluates both of its operands and returns the value of the one on the right-hand side. You can also choose between alternatives using the ternary ?: operator, as in 1 #define Max (a,b) ( (a) > (b) ? (a) : (b)) 2 (but see the warning about repeated parameters above).
How to define a variadic macro in C99?
Variable-length argument lists C99 added variadic macros that may have a variable number of arguments; these are mostly useful for dealing with variadic functions (like printf) that also take a variable number of arguments. To define a variadic macro, define a macro with arguments where the last argument is three periods: .
Is it best to mark macro names by capitalization?
For this reason it is generally best to avoid side-effects in macro arguments, and to mark macro names (e.g. by capitalization) to clearly distinguish them from function names, where this issue doesn’t come up. 1.3. Variable-length argument lists
Can you run 5 macros at the same time?
So running all 5 macros at the same time would require a lot of work. But OP mentioned in the comment that running all 5 macros sequentially would be an option. Now running this macro will run all the specified macros sequentially. Thanks for contributing an answer to Stack Overflow!
Which is more sophisticated assert or file macro?
The assert macro is a more sophisticated version, which uses the built-in macros __FILE__ (which expands to the current source file as a quoted string) and __LINE__ (which expands to the current source line number, not quoted) to not only print out an offending expression, but also the location of it in the source. 3.5. Big macros