Created
July 26, 2013 18:07
-
-
Save aprell/6090933 to your computer and use it in GitHub Desktop.
Reminder: Never ever make this mistake again.
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
| #include <stdio.h> | |
| #define A baz | |
| int main(void) | |
| { | |
| #if A == foo || A == bar | |
| printf("Wrooong!\n"); | |
| #endif | |
| return 0; | |
| } |
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
| #include <stdio.h> | |
| #define foo 1 | |
| #define bar 2 | |
| #define baz 3 | |
| #define A baz | |
| int main(void) | |
| { | |
| #if A == foo || A == bar | |
| printf("Right!\n"); | |
| #endif | |
| return 0; | |
| } |
Laut Doku müsste das gehen, tut es aber nicht, obwohl in der Expansion das richtige raus kommt (ich hab den Compiler doch angeschmissen):
#include <stdio.h>
#define A baz
#define exp(x) str(x)
#define str(x) #x
int main(void)
{
#if A == "foo"
printf("Wrooong!\n");
#endif
return 0;
}
Author
Wenn der Präprozessor wenigstens warnen würde, dass er keine Zeichenketten vergleichen kann...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hätte nicht auch folgendes gehen können:
Bin zu faul den compiler anzuschmeißen ;)