“数组"的定义是什么?在 C? [英] What is the definition of "array" in C?

查看:15
本文介绍了“数组"的定义是什么?在 C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准对数组类型进行了细致的定义,但我没有看到数组的任何定义.

The standard defines array type meticulously, but I don't see any definition for array.

我们可能会说数组类型的对象",但这并不正确,因为无类型对象(例如由 malloc 分配的空间)被描述为数组.

We might say "object of array type", however that can't be right as untyped objects (e.g. space allocated by malloc) is described as an array.

动机:fprintf (C11 7.21.6.1/8) 中 %s 的规范说:

Motivation: The specification for %s in fprintf (C11 7.21.6.1/8) says:

参数应该是指向字符类型数组的初始元素的指针

the argument shall be a pointer to the initial element of an array of character type

但是取代码 char s[] = "hello";printf("%s", s+1); 然后我们传递了一个指向第二个元素的指针.该定义似乎假设 array 意味着 任何一组连续对象.

but take the code char s[] = "hello"; printf("%s", s+1); then we passed a pointer to the second element. That definition appears to be assuming that array means any set of contiguous object(s).

看到我收到了一些不清楚你在问什么"的票,我的问题是:所使用的术语数组的定义是什么通过 ISO/IEC 9899:2011 ?

seeing as I have picked up some "unclear what you're asking" votes, my question is: What is that definition of the term array as used by ISO/IEC 9899:2011 ?

推荐答案

数组定义在 C 标准,6.2.5,第 20 段:

Arrays are defined in the C Standard, 6.2.5, paragraph 20:

一个数组类型描述了一个连续分配的非空集合具有特定成员对象类型的对象,称为元素类型.数组类型的特征在于它们的元素类型和数量数组中的元素.数组类型据说是从它的元素类型,如果其元素类型为T,则数组类型为有时称为T 数组".数组类型的构造来自元素类型的称为数组类型派生".

An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T, the array type is sometimes called ‘‘array of T’’. The construction of an array type from an element type is called ‘‘array type derivation’’.

这篇关于“数组"的定义是什么?在 C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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