什么是C中的复合类型? [英] What is a composite type in C?

查看:98
本文介绍了什么是C中的复合类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自§6.2.7.5(第66页):

EXAMPLE给出以下两个文件作用域声明:

EXAMPLE Given the following two file scope declarations:

int f(int (*)(), double (*)[3]);  
int f(int (*)(char *), double (*)[]);  

该函数产生的复合类型为:

The resulting composite type for the function is:

int f(int (*)(char *), double (*)[3]);

在示例上方,他们解释了复合类型是与两种不同类型兼容的类型.我会直觉地理解复合类型"一词的意思是结构和联合",这似乎是偏离目标的.

Above the example, they explain that a composite type is a type, compatible with two different types. I would intuitively understand the phrase "composite type" as meaning "structures and unions", which appears to be way off-target.

C中的复合类型是什么,它的用途是什么?有人可以详细解释上面的示例吗?

推荐答案

我会直觉地将短语复合类型"理解为结构和联合",这似乎偏离了目标.

I would intuitively understand the phrase "composite type" as meaning "structures and unions", which appears to be way off-target.

在C语言定义中,数组和结构是 aggregate 类型(由多个元素组成的类型).工会是他们自己的动物,因为它们一次只能承担一个要素的价值.

In the C language definition, arrays and structs are aggregate types (types composed of multiple elements). Unions are kind of their own animal, since they can only take on the value of one element at a time.

复合类型对于编译器实现者来说是一个更大的问题,而不是我们惯用的代码猴子.您和我都不会尝试定义复合类型或声明该类型的对象.

Composite types are more of an issue for compiler implementors, rather than us run-of-the-mill code monkeys. You and I would not attempt to define a composite type, or declare objects of that type.

在给定的示例中,对于函数f,您有两个文件范围声明,它们彼此之间略有不同.根据6.2.7/3中介绍的规则,编译器确定一个对两者都适用的类型,以便它可以在编译时强制执行类型语义(即,可以适当地检查对f的任何调用,即使稍有改动也可以).不同的声明),并生成适当的机器码来调用该函数.

In the example given, you have two file scope declarations for a function f that are slightly different from each other. Based on the rules presented in 6.2.7/3, the compiler determines a type that works for both, such that it can enforce type semantics at compile time (i.e., any calls to f can be properly checked, even with the slightly different declarations) and generate the proper machine code to call the function.

这篇关于什么是C中的复合类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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