<分区>
我在阅读asterisk源码的时候,发现了这样一行代码:
#define ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a]))
我经常使用a[0]
或(*a)
,但他们使用(0[a])
。你能帮我更清楚地解释一下吗?
<分区>
我在阅读asterisk源码的时候,发现了这样一行代码:
#define ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a]))
我经常使用a[0]
或(*a)
,但他们使用(0[a])
。你能帮我更清楚地解释一下吗?
最佳答案
a[0]
被编译器翻译为 *(a+0)
。 0[a]
翻译为*(0+a)
。因此,a[0]
和 0[a]
是等价的。
来自 C99 标准:
6.5.2.1 Array subscripting
2 A postfix expression followed by an expression in square brackets
[]
is a subscripted designation of an element of an array object. The definition of the subscript operator[]
is thatE1[E2]
is identical to(*((E1)+(E2)))
.
关于c - 这是什么意思 : sizeof(0[a]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32492067/