我太孤陋了, 原来现在的c(GNU C)里面还可以这样来初始化数组…

啥都不说了, sigh

transparentmask$ gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5664~89/src/configure –disable-checking –enable-werror –prefix=/usr –mandir=/share/man –enable-languages=c,objc,c++,obj-c++ –program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ –with-slibdir=/usr/lib –build=i686-apple-darwin10 –program-prefix=i686-apple-darwin10- –host=x86_64-apple-darwin10 –target=i686-apple-darwin10 –with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5664)

transparentmask$ gcc test.c -o test

transparentmask$ ./test
111122211

transparentmask$ cat test.c

#include <stdio.h>
#include <stdlib.h>

int main() {
	char s[10] = {
		[0 ... 8] = '1',
		[4 ... 6] = '2',
		[9] = 0
	};
	printf("%s\n", s);

	return 0;
}

《我太孤陋了, 原来现在的c(GNU C)里面还可以这样来初始化数组…》有4个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注