51 lines
693 B
Markdown
51 lines
693 B
Markdown
# GCC 扩展 之 数组初始化
|
||
|
||
* 示例 1:
|
||
|
||
```cpp
|
||
#include <stdio.h>
|
||
|
||
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 <stdio.h>
|
||
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;
|
||
}
|
||
```
|