我有以下C代码示例:
int f(const int farg[const 5])
{
}数组大小的附加const是做什么的?当我忽略了康斯特时,有什么区别呢?
发布于 2014-07-08 08:46:31
int d(const int darg[5])意味着darg是指向const int的指针。
int e(int earg[const 5])意味着earg是指向int的const指针。这是一个c99特性。在参数声明中,T A[qualifier-list e]与T * qualifier-list A等效。
当然(从上面):
int f(const int farg[const 5])表示farg是指向const int的const指针。
发布于 2014-07-08 09:06:32
数组大小的附加const是做什么的?
C11: 6.7.6.3:
参数声明为“‘类型数组’”应调整为指向type’’,的‘限定指针,其中类型限定符(如果有的话)是在数组类型派生的
[和]中指定的。
这意味着
int f(const int farg[const 5]) 将调整为
int f(const int *const farg) 当我忽略了康斯特时,有什么区别呢?
省略后,它相当于
int f(const int frag[5]) //or int f(const int frag[])这最终相当于
int f(const int *farg)https://stackoverflow.com/questions/24627309
复制相似问题