diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/config.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/config.json" index 1def284e5fc138be0c0c5c215485f10457bddd2c..4b22871247fe79422e5537f76c4900c18d545964 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/config.json" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/config.json" @@ -6,5 +6,7 @@ "C语言" ], "children": [], - "export": [] + "export": [ + "undef.json" + ] } \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.json" new file mode 100644 index 0000000000000000000000000000000000000000..a9110066bbba949b48c69daa68bcefb4a4d78465 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "undef.md" +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.md" new file mode 100644 index 0000000000000000000000000000000000000000..dca9a190b5bf250beb3c5e5731cb5d7dd07cb0be --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/3.#undef\346\214\207\344\273\244/undef.md" @@ -0,0 +1,40 @@ +# 使用 `#undef` + +C语言的宏定义可以通过`#undef`取消定义,下面程序的输出是哪个选项? +```c +#include + +#define next(x) x+1 +#undef next + +int main(int argc, char** args){ + printf("%d", next(10)); + return 0; +} +``` + +## 答案 + +```c +error: use of undeclared identifier 'next' +``` + +## 选项 + +### 直接定义宏字符串常量 + +```c +10 +``` + +### 两个字符串常量组合 + +```c +11 +``` + +### 宏直接拼接 + +```c +12 +``` \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/config.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/config.json" index 1def284e5fc138be0c0c5c215485f10457bddd2c..aef9545e62f97c8b2b6228d41d2e1fea4c20a48e 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/config.json" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/config.json" @@ -6,5 +6,8 @@ "C语言" ], "children": [], - "export": [] + "export": [ + "ifdef01.json", + "ifdef02.json" + ] } \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.json" new file mode 100644 index 0000000000000000000000000000000000000000..e667780dce18fc11d15c6ffceb9d60a01c007f6b --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "ifdef01.md" +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.md" new file mode 100644 index 0000000000000000000000000000000000000000..8a8ab8f7a39f8646a45754e288285d4fcfcab548 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef01.md" @@ -0,0 +1,114 @@ +# 使用 `#undef` + +C语言的宏定义可以通过`#ifdef`,`#else`,`#endif`包含条件编译,下面输出11的程序是? + +## 答案 + +```c +#include + +#define add_encode(x) x+1 +#define sub_encode(x) x-1 +#define unit_encode(x) x + + +#define USE_INC + +#ifdef USE_INC + #define encode add_encode +#else + #ifdef USE_SUB + #define encode sub_encode + #else + #define encode unit_encode + #endif +#endif + +int main(int argc, char** args){ + printf("%d", encode(10)); + return 0; +} +``` + +## 选项 + +### 直接定义宏字符串常量 + +```c +#include + +#define add_encode(x) x+1 +#define sub_encode(x) x-1 +#define unit_encode(x) x + + +#define USE_SUB + +#ifdef USE_INC + #define encode add_encode +#else + #ifdef USE_SUB + #define encode sub_encode + #else + #define encode unit_encode + #endif +#endif + +int main(int argc, char** args){ + printf("%d", encode(10)); + return 0; +} +``` + +### 两个字符串常量组合 + +```c +#include + +#define add_encode(x) x+1 +#define sub_encode(x) x-1 +#define unit_encode(x) x + + +#define USE_UNIT + +#ifdef USE_INC + #define encode add_encode +#else + #ifdef USE_SUB + #define encode sub_encode + #else + #define encode unit_encode + #endif +#endif + +int main(int argc, char** args){ + printf("%d", encode(10)); + return 0; +} +``` + +### 宏直接拼接 + +```c +#include + +#define add_encode(x) x+1 +#define sub_encode(x) x-1 +#define unit_encode(x) x + +#ifdef USE_INC + #define encode add_encode +#else + #ifdef USE_SUB + #define encode sub_encode + #else + #define encode unit_encode + #endif +#endif + +int main(int argc, char** args){ + printf("%d", encode(10)); + return 0; +} +``` \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.json" new file mode 100644 index 0000000000000000000000000000000000000000..a664b5074beda41180106bf8ad487565fd983802 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "ifdef02.md" +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.md" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.md" new file mode 100644 index 0000000000000000000000000000000000000000..a52c6ca7d802396de0df507d155619e13f76a06f --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/4.\346\235\241\344\273\266\347\274\226\350\257\221/ifdef02.md" @@ -0,0 +1,72 @@ +# 使用 `#undef` + +C语言的宏定义可以通过`#ifdef`,`#else`,`#endif`包含条件编译,下面输出10的程序是? + +## 答案 + +```c +#include + +#define DEBUG + +int main(int argc, char** args){ + #ifdef DEBUG + printf("%d", encode(10)); + #else + printf("%d", encode(11)); + #endif + return 0; +} +``` + +## 选项 + +### 直接定义宏字符串常量 + +```c +#include + +int main(int argc, char** args){ + #ifdef DEBUG + printf("%d", encode(10)); + #else + printf("%d", encode(11)); + #endif + return 0; +} +``` + +### 两个字符串常量组合 + +```c +#include + +#define DEBUG +#undef DEBUG + +int main(int argc, char** args){ + #ifdef DEBUG + printf("%d", encode(10)); + #else + printf("%d", encode(11)); + #endif + return 0; +} +``` + +### 宏直接拼接 + +```c +#include + +#define DEBUG + +int main(int argc, char** args){ + #ifdef DEBUG + printf("%d", encode(11)); + #else + printf("%d", encode(10)); + #endif + return 0; +} +``` \ No newline at end of file