static uint8_t togglecode[256] = {
[0x3A] CAPSLOCK,
[0x45] NUMLOCK,
[0x46] SCROLLLOCK
};
这里的[0x3A]
是什么意思?我只学过像 int a[2] = {1, 2};
最佳答案
这意味着初始化数组的第n个元素。您给出的示例意味着:
togglecode[0x3A] == CAPSLOCK
togglecode[0x45] == NUMLOCK
togglecode[0x46] == SCROLLLOCK
这些被称为 "designated initializers" ,实际上是 C99 标准的一部分。但是,没有 =
的语法则不然。从该页面:
An alternative syntax for this which has been obsolete since GCC 2.5 but GCC still accepts is to write
[index]
before the element value, with no=
.
关于c - C 中数组初始化中的方括号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43873929/