How do you define a multiline macro in C?
Asked
Active
Viewed 2.6k times
16
-
2Use '\' at line endings. – Trevor Hickey Oct 02 '16 at 20:09
3 Answers
28
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;
}

shriroop_
- 775
- 6
- 15
3
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\
}\
}

Luis B
- 1,684
- 3
- 15
- 25