From 08cbb36fe2edae1fa051d6911894a94f6f25c8dd Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Fri, 16 Oct 2020 10:18:23 +0800 Subject: [PATCH] =?UTF-8?q?GCC=20=E6=89=A9=E5=B1=95=20=E4=B9=8B=20?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Language/C/GCC_扩展_数组初始化.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Software/Development/Language/C/GCC_扩展_数组初始化.md diff --git a/Software/Development/Language/C/GCC_扩展_数组初始化.md b/Software/Development/Language/C/GCC_扩展_数组初始化.md new file mode 100644 index 0000000..0fd91e0 --- /dev/null +++ b/Software/Development/Language/C/GCC_扩展_数组初始化.md @@ -0,0 +1,50 @@ +# GCC 扩展 之 数组初始化 + +* 示例 1: + +```cpp +#include + +int array[10] = +{ + [0 ... 9] = 0, + [8] = 8, + [2 ... 2] = 2, + [5 ... 7] = 5 +}; + +int main() +{ + int i = 0; + + for (i = 0; i < 10; i++) + printf("%d/n", array[i]); + return 0; +} +``` + +* 示例 2: + +```cpp +#include +struct StObErrorStringMap +{ + const char *jdbc_state; + const char *odbc_state; +}; + +struct StObErrorStringMap arr[10] = +{ + [0 ...9] = {(const char*)"HY000", (const char*)"S1000"}, + [1] = { (const char*)"HY001", (const char*)"S1000" }, +}; + +int main() +{ + int i = 0; + + for (i = 0; i < 10; i++) + printf("%s\n", arr[i].jdbc_state); + return 0; +} +```