初始化时,可随意指定初始化的元素或者元素的范围。
附gnu c 手册。
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html
代码:
test.c
#include <stdio.h>
static const unsigned int boot_gdt[] __attribute__((aligned())) = {
[] = 0x11223344,
[] = 0x11223344,
[ ... ] = 0x32,
[] = 0x11223344
}; typedef struct { unsigned long int pte; } pte_t; int main(void){
int len = sizeof(boot_gdt)/sizeof(int) - ;
printf("the len of boot_gdt is %d \n", len + );
for(int i = ; i <= len; i++){
printf("the %d data is 0x%x\n", i, boot_gdt[i]);
}
}
http://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Initializing-Arrays
编译:
$ gcc -o test test.c -std=c99
运行:
$ ./test
the len of boot_gdt is 16
the 0 data is 0x0
the 1 data is 0x11223344
the 2 data is 0x11223344
the 3 data is 0x32
the 4 data is 0x32
the 5 data is 0x32
the 6 data is 0x32
the 7 data is 0x32
the 8 data is 0x32
the 9 data is 0x32
the 10 data is 0x32
the 11 data is 0x0
the 12 data is 0x0
the 13 data is 0x0
the 14 data is 0x0
the 15 data is 0x11223344