How do you define a multiline macro in C?
We can write multiline macros like functions, but for macros, each line must be terminated with backslash '\' character. If we use curly braces '{}' and the macros is ended with '}', then it may generate some error. So we can enclose the entire thing into parenthesis.
How do you define a multiline macro in C? Use '\' at line endings.
A nested macro instruction definition is a macro instruction definition you can specify as a set of model statements in the body of an enclosing macro definition. This lets you create a macro definition by expanding the outer macro that contains the nested definition.
You cannot define macros in other macros, but you can call a macro from your macro, which can get you essentially the same results.
End every line of definition of macro with a \
#include <stdio.h>
#define MAX(a,b) {\
printf("%d ", a); \
printf("%d\n", b); \
}
int main()
{
printf("Hello, World!\n");
MAX(4, 5);
return 0;
}
Use \
to escape line return:
#define MULTILINE_MACRO()\
line1\
line2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With