array []括号内的静态关键字 [英] static keyword inside array [] brackets

查看:84
本文介绍了array []括号内的静态关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了 static 关键字的新用法。
static 在这里表示什么?

  void fun( int some_array [static 7]); 

编辑:有人可以举例说明这可能有用吗?

解决方案

标准在6.7.6.3中说过:


参数声明为''数组类型''应调整为
''符合指针的类型'',其中类型限定符(如果有)为
数组类型派生的[和]。如果
关键字static也出现在数组类型
derivation
的[和]中,则对于函数的每次调用,
的值对应于实际值参数应该提供对数组中第一个
元素的访问,其中至少有与
size表达式指定的元素一样多的元素。


这是C99中引入的功能。所以你有它: some_array 必须至少有7个元素长。




正如他们所说,如果没有关键字 static


I recently came across new use of static keyword. What does static mean here?

void fun(int some_array[static 7]);

EDIT : can someone give an example where this can be useful?

解决方案

The standard says in 6.7.6.3:

A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression.

It's a feature introduced in C99. So there you have it: some_array must be at least 7 elements long.


As they say, there can't be a new standard without a new usage for the keyword static.

这篇关于array []括号内的静态关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆