Created
July 16, 2017 17:42
-
-
Save qeedquan/af7d62dd65c6b3c4394f83e813726248 to your computer and use it in GitHub Desktop.
Using macro to create a multiline string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// how to do make a string out of multiple lines | |
// using the preprocessor | |
#include <stdio.h> | |
#define STRINGIFY(...) #__VA_ARGS__ | |
int | |
main(void) | |
{ | |
char *s = STRINGIFY( | |
she walked by the shore | |
staring into the stars. | |
\n\n\b | |
testify brother; for ye | |
shall receive covfefe punishment. | |
\n\n\b | |
1, 2, 3, 4 | |
\n\n\b | |
kidz war in the trenches, | |
not a sight to behold. | |
\n\n\b | |
"add some string so i can\ | |
subtract some doubt \ | |
or not" | |
\n\n\b | |
#define A(x) MEH | |
A(10) | |
// include gets precedence, it will expand first then stringify | |
// uncomment to see | |
// #include <stdio.h> | |
\n\n\b | |
the end. | |
); | |
printf("%s\n", s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment