c - array [] 括号内的 static 关键字

标签 c arrays function static

<分区>

我最近发现了 static 关键字的新用法。 static 在这里是什么意思?

void fun(int some_array[static 7]);

编辑:有人可以举一个有用的例子吗?

最佳答案

标准在 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.

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


正如他们所说,如果关键字 static 没有新用法,就不可能有新标准。

关于c - array [] 括号内的 static 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14942520/

相关文章:

c - 在冒泡排序中使用第二个for循环

c - btree 实现中的段错误

javascript - 将多个 CSS 类存储在一个数组中

java - 为什么 Java 没有匿名映射或数组和列表?

c - 这个带有多个值(变量)的返回语句是如何工作的?

c - 如果在已经返回的线程上调用 pthread_detach 会发生什么

C - Ncurses - 如何阻止光标越过墙壁(由一堆字符组成的墙壁)

objective-c - 获取n维数组中的下一个元素

python - 将两个字符串连接成可调用字符串 'moduleA' + 'func1' 进入 moduleA.func1()

node.js - Azure Function 将 SQL 服务器与浏览器中的空白页连接