Last active
December 17, 2015 06:19
-
-
Save jballanc/5564479 to your computer and use it in GitHub Desktop.
Fun 'n Games with C: An innocuous seeming pair of parentheses turns an infinite loop into a end-run around the C preprocessor.
This file contains 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
#include <stdio.h> | |
void method(char* first, char* second, char* third) | |
{ | |
printf("method arguments - first: %s, second: %s, third: %s\n", first, second, third); | |
return; | |
} | |
void wrapped_method(char* first, char* second, char* third); | |
#define method(first, second, third) wrapped_method((second), (third), (first)) | |
void wrapped_method(char* first, char* second, char* third) | |
{ | |
printf("wrapped_method arguments - first: %s, second: %s, third: %s\n", first, second, third); | |
printf("Calling the *real* method..."); | |
(method)(second, third, first); //remove the parens around "method" and the result is very different... | |
return; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
printf("Calling: method(one, two, three)\n"); | |
method("one", "two", "three"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment