Created
July 12, 2020 07:24
-
-
Save gjlmotea/6bb3069b54a687d7f935bb7e58cb583b to your computer and use it in GitHub Desktop.
C macro陷阱
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> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
#define PI 3.14159 | |
#define Square(x) x*x | |
#define Square_(x) x*(x) | |
#define Square__(x) ((x)*(x)) | |
printf("%f\n", PI); | |
printf("\n"); | |
printf("%d\n", Square(5)); | |
printf("%d\n", Square(2+3)); | |
printf("\n"); | |
printf("%d\n", Square_(5)); | |
printf("%d\n", Square_(2+3)); | |
printf("\n"); | |
printf("%d\n", Square__(5)); | |
printf("%d\n", Square__(2+3)); | |
printf("\n"); | |
int i; | |
i = 4; | |
printf("%d\n", Square__(i++)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment