什么是那些怪阵尺寸在C99 [*]和[静态]? [英] What are those strange array sizes [*] and [static] in C99?

查看:218
本文介绍了什么是那些怪阵尺寸在C99 [*]和[静态]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,下面的函数原型是C99和C11有效的:

Apparently the following function prototypes are valid in C99 and C11:

void foo(int a[const *]);

void bar(int a[static volatile 10]);

什么是那些奇怪的下标符号 * 静态和CV预选赛?

难道他们帮助从变长数组区分静态类型的数组?或者他们只是语法糖?

Do they help distinguish statically typed arrays from variable-length arrays? Or are they just syntactic sugar?

推荐答案

静态参数数组声明

 void f(int a[static 10]);

静态这里是一个迹象表明参数 A 是一个指向 INT ,但该数组客体(其中 A 是一个指向它的第一个元素)至少有 10 元素。

static here is an indication that parameter a is a pointer to int but that the array objet (where a is a pointer to its first element) has at least 10 elements.

一个编译器,然后假设˚F的说法正确的是不是 NULL ,因此它可以进行一些优化。 GCC 目前没有执行优化():

A compiler has then the right to assume f argument is not NULL and therefore it could perform some optimizations. gcc currently performs no optimization (source):

静态的参数组声明中提供的信息不用于优化。它可能是有意义的在与prefetching工作配合使用,在未来的。

"The information provided by static in parameter array declarators is not used for optimization. It might make sense to use it in future in conjunction with work on prefetching."

预选赛中,参数数组声明

void g(int a[cvr 10]);

先按g A CVR 的指针 INT CVR 的是常量挥发性限制预选赛)。例如,常量这意味着 A 常量指针 INT (即键入为int * const的)。

inside g a is a cvr pointer to int (cvr is const, volatile or restrict qualifier). For example, with const it means a is a const pointer to int (i.e., type int * const).

因此​​,一个参数声明:

So a parameter declaration:

T param[cvr e] 

是相同的参数声明:

is the same as a parameter declaration:

T * cvr param

* 参数数组声明

void h(int a[*]);

[*] 在函数声明正式阵列参数声明(即不是函数定义的一部分)表示,正式数组是一个可变长度的数组。

The [*] in a formal array parameter declaration in a function declaration (that is not part of a function definition) indicates that the formal array is a variable length array.

这篇关于什么是那些怪阵尺寸在C99 [*]和[静态]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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