Created
June 23, 2012 11:20
-
-
Save pghalliday/2977939 to your computer and use it in GitHub Desktop.
Macro Pasting Hell
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
| #define CALLONE(FUNCTION, ARGS...) FUNCTION(1 , ##ARGS) | |
| CALLONE(add, CALLONE(addOne)); | |
| /* expands to */ | |
| add(1, CALLONE(addOne)); |
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
| #define _CALLONE(FUNCTION, ARGS...) FUNCTION(1 , ##ARGS) | |
| #define CALLONE(FUNCTION, ARGS...) _CALLONE(FUNCTION, ARGS) | |
| CALLONE(add, CALLONE(addOne)); | |
| /* expands to */ | |
| add(1, addOne(1, )); |
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
| #define PASTE(ARG1, ARG2) ARG1 ## ARG2 | |
| PASTE(Hello, World)(); | |
| /* expands to */ | |
| HelloWorld(); |
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
| #define PASTE(ARG1, ARG2) ARG1 ## ARG2 | |
| #define HELLO Hello | |
| PASTE(HELLO, World)(); | |
| /* expands to */ | |
| HELLOWorld(); |
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
| #define _PASTE(ARG1, ARG2) ARG1 ## ARG2 | |
| #define PASTE(ARG1, ARG2) PASTE(ARG1, ARG2) | |
| #define HELLO Hello | |
| PASTE(HELLO, World)(); | |
| /* expands to */ | |
| HelloWorld(); |
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
| #define ISEMPTY(ARGS...) /* Too complicated to put here, see http://gustedt.wordpress.com/2010/06/08/detect-empty-macro-arguments/ */ | |
| #define _PASTE(ARG1, ARG2) ARG1 ## ARG2 | |
| #define PASTE(ARG1, ARG2) PASTE(ARG1, ARG2) | |
| #define CALLONE0(FUNCTION, ARGS...) FUNCTION(1, ARGS) | |
| #define CALLONE1(FUNCTION, ARGS...) FUNCTION(1) | |
| #define CALLONE(FUNCTION, ARGS...) PASTE(CALLONE,ISEMPTY(ARGS))(FUNCTION, ARGS) | |
| CALLONE(add, CALLONE(addOne)); | |
| /* expands to */ | |
| add(1, addOne(1)); |
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
| #define CALLONE(FUNCTION, ARGS...) FUNCTION(1 , ##ARGS) | |
| CALLONE(myFunc); | |
| /* expands to */ | |
| myFunc(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment