How do you define a multiline macro in C?
How do you define a multiline macro in C? [duplicate]
Asked Answered
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
Below are two C macros that are multiline
#define for_loop_begin(size)\
for (int i = 0; i < size; i++) \
{ \
for (int j = 0; j < size; j++) {
#define for_loop_end\
}\
}
© 2022 - 2024 — McMap. All rights reserved.