了解C11类型层次 [英] Understanding the C11 type hierarchy

查看:159
本文介绍了了解C11类型层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想充分了解C11语言和present它图形化(树图将是完美的)的类型层次。该标准没有为这个问题提供任何人物 - 有30个点描述个别类型和它们之间的关系。我想画它。

N1570 201X委员会草案:

我试图从获取 ISO / IEC 9899开始并提取文档中的6.2.5节所有必需的语句。然后,我开始重新排列的知识以树的形式。让我present我的工作分两个步骤。

步骤1:1-15分

提取知识(点段内6.2.5 +指定生产):


  • 1 类型的=的对象类型 + 函数类型的;

  • 4 标准符号整型 = 符号字符短整型 INT 长整型得到long long int ;

  • 4 符号整型的=标准符号整型+的扩展符号整型的;

  • 6 标准的无符号整型 = _Bool unsigned char型无符号的短整型 unsigned int类型,<$ C> $ C>无符号长long int类型;

  • 6 无符号整型的=标准的无符号整型+的扩展无符号整型的;

  • 7 标准的整数类型的=标准符号整型+标准的无符号整型;

  • 7 扩展整型的=延长符号整型+扩展的无符号整型;

  • 10的真正的浮点类型 = 浮动双击长双;

  • 11 复杂类型 = 浮动_Complex 双_Complex 长双_Complex ;

  • 12 浮点类型的=实浮点型+复杂的类型;

  • 14 基本类型 = 字符 +符号整型+无符号整型+浮点类型;

  • 15 字符类型 = 字符符号字符 unsigned char型

和所得结构:

 类型
    对象类型
    函数类型
基本类型
    烧焦
    sίgned整数类型
        标准sίgned整数类型
            符号的字符,短整型,整型,长整型,得到long long int
        扩展sίgned整数类型
    unsίgned整数类型
        标准unsίgned整数类型
            _Bool,unsigned char型,无符号短整型,无符号整型,
            unsigned long int类型,unsigned long类型长整型
        扩展unsίgned整数类型
    浮点类型
        真正的浮点类型
            浮动,双,长双
        复杂类型
            浮_Complex,双_Complex,长双_Complex
标准的整数类型
    标准sίgned整数类型
    标准unsίgned整数类型
扩展整型
    扩展sίgned整数类型
    扩展unsίgned整数类型
字符类型
    字符,符号的字符,无符号的字符

步骤2:16-24分

剩下的语句:


  • 16 枚举类型的;

  • 17 整数类型 = 字符 +符号整型+无符号整型+枚举类型;

  • 17的真正的类型的=整数类型+实浮点类型;

  • 18 算术类型的=整数类型+浮点类型;

  • 20 派生类型 = 数组类型结构类型 union类型函数类型指针类型原子类型的;

  • 21的标量类型的=算术类型+指针类型;

  • 21 聚合类型的=数组类型+结构类型;

  • 24 导出声明符类型的=数组类型+函数类型+指针类型。

和最终的C11型的体系结构:

 类型
    对象类型
    函数类型
基本类型
    烧焦
    sίgned整数类型
        标准sίgned整数类型
            符号的字符,短整型,整型,长整型,得到long long int
        扩展sίgned整数类型
    unsίgned整数类型
        标准unsίgned整数类型
            _Bool,unsigned char型,无符号短整型,无符号整型,
            unsigned long int类型,unsigned long类型长整型
        扩展unsίgned整数类型
    浮点类型
        真正的浮点类型
            浮动,双,长双
        复杂类型
            浮_Complex,双_Complex,长双_Complex
标准的整数类型
    标准sίgned整数类型
    标准unsίgned整数类型
扩展整型
    扩展sίgned整数类型
    扩展unsίgned整数类型
字符类型
    字符,符号的字符,无符号的字符
真正的类型
    整数类型
        烧焦
        sίgned整数类型
            标准sίgned整数类型
                符号的字符,短整型,整型,长整型,得到long long int
            扩展sίgned整数类型
        unsίgned整数类型
            标准unsίgned整数类型
                _Bool,unsigned char型,无符号短整型,无符号整型,
                unsigned long int类型,unsigned long类型长整型
            扩展unsίgned整数类型
        枚举类型
    真正的浮点类型
        浮动,双,长双
标量类型
    算术类型
        整数类型
            烧焦
            sίgned整数类型
                标准sίgned整数类型
                    符号的字符,短整型,整型,长整型,得到long long int
                扩展sίgned整数类型
            unsίgned整数类型
                标准unsίgned整数类型
                    _Bool,unsigned char型,无符号短整型,无符号整型,
                    unsigned long int类型,unsigned long类型长整型
                扩展unsίgned整数类型
            枚举类型
        浮点类型
            真正的浮点类型
                浮动,双,长双
            复杂类型
                浮_Complex,双_Complex,长双_Complex
    指针类型
派生类型
    数组类型
    结构类型
    unίon类型
    函数类型
    指针类型
    原子类型
聚合类型
    数组类型
    结构类型
导出声明符类型
    数组类型
    结构类型
    指针类型

现在我需要减轻结构(理想情况下,以一棵树),或者找到一个更棘手的方式重新present关系。我想用一个漂亮的cheet表为C11打字系统就出来了。任何想法?


解决方案

从问题的第二步骤得到C11类型的混乱结构可以通过去除/减少不太重要节点进行简化和下放部分冗余/子公司信息被$ p $通过其他方式psented。

我提出以下五步算法是:


  1. 所有的拆卸延长的整数类型(严格符合实现假定);

  2. 的减少的标准的整数类型(因为他们没有任何更多的分区类型);

  3. 分组结构:

    1. 系统的标量类型的VS的聚合类型的一双子树(重psented为一棵树$ P $),

    2. A 基本类型的VS的派生类型的一双子树(通过重新着色区域psented $ P $),

    3. 真正的类型的和的导出声明符类型的(再presented作为这些抚摸分区域),

    4. 字符类型的(重不同的文字颜色psented $ P $);


  4. 场外标准生产中的应用:的对象类型的=的标量类型 + 聚合类型的;

  5. 的补充的对象类型的缺失的 union类型的和的原子类型

由此产生的C11型系统摘要如下所示:

C11型层次结构

灰色卒中/地区引入以增加树的可读性。

类型摘要不包括类型声明完整性的概念,因为它是一种状态,一个翻译单元内的一个特定点观察的。在运行时,所有的对象和函数是的完整的类型的实例。在空隙类型是一个例外,但是,作为一个没有型(或任何类型的指针的情况下),它被故意从图中排除。

常量挥发性限制 _Atomic 键入预选赛的哪个,相反的类型说明符的的的派生类型的,不能递归应用。这些的任意组合可以prePEND任何类型定义(只要它是有意义)。因此,包括它们在图中也同时不引入任何合适的信息,复杂化了。明显的异常,使 _Atomic(类型)结构,这是考虑到作为一个的类型说明符的的的原子类型 - 中的派生类型之一的在C11标准中列出

I would like to fully understand type hierarchy of the C11 language and present it graphically (a tree diagram would be perfect). The standard does not provide any figure for this issue – there are 30 points describing individual types and relations between them. I'd like to draw it.

My attempt started from obtaining the ISO/IEC 9899:201x Committee Draft N1570 and extracting all the essential statements from section 6.2.5 of the document. Then, I started to rearrange the knowledge in a form of a tree. Let me present my work in two steps.

Step 1: points 1–15

The extracted knowledge (point within section 6.2.5 + specified production):

  • 1 types = object types + function types;
  • 4 standard signed integer types = signed char, short int, int, long int, long long int;
  • 4 signed integer types = standard signed integer types + extended signed integer types;
  • 6 standard unsigned integer types = _Bool, unsigned char, unsigned short int, unsigned int, unsigned long int, unsigned long long int;
  • 6 unsigned integer types = standard unsigned integer types + extended unsigned integer types;
  • 7 standard integer types = standard signed integer types + standard unsigned integer types;
  • 7 extended integer types = extended signed integer types + extended unsigned integer types;
  • 10 real floating types = float, double, long double;
  • 11 complex types = float _Complex, double _Complex, long double _Complex;
  • 12 floating types = real floating types + complex types;
  • 14 basic types = char + signed integer types + unsigned integer types + floating types;
  • 15 character types = char, signed char, unsigned char.

And the resulting structure:

types
    object types
    function types
basic types
    char
    sίgned integer types
        standard sίgned integer types
            signed char, short int, int, long int, long long int
        extended sίgned integer types
    unsίgned integer types
        standard unsίgned integer types
            _Bool, unsigned char, unsigned short int, unsigned int,
            unsigned long int, unsigned long long int
        extended unsίgned integer types
    floating types
        real floating types
            float, double, long double
        complex types
            float _Complex, double _Complex, long double _Complex
standard integer types
    standard sίgned integer types
    standard unsίgned integer types
extended integer types
    extended sίgned integer types
    extended unsίgned integer types
character types
    char, signed char, unsigned char

Step 2: points 16–24

The remaining statements:

  • 16 enumerated types;
  • 17 integer types = char + signed integer types + unsigned integer types + enumerated types;
  • 17 real types = integer types + real floating types;
  • 18 arithmetic types = integer types + floating types;
  • 20 derived types = array types, structure types, union types, function types, pointer types, atomic types;
  • 21 scalar types = arithmetic types + pointer types;
  • 21 aggregate types = array types + structure types;
  • 24 derived declarator types = array types + function types + pointer types.

And the final C11 type system structure:

types
    object types
    function types
basic types
    char
    sίgned integer types
        standard sίgned integer types
            signed char, short int, int, long int, long long int
        extended sίgned integer types
    unsίgned integer types
        standard unsίgned integer types
            _Bool, unsigned char, unsigned short int, unsigned int,
            unsigned long int, unsigned long long int
        extended unsίgned integer types
    floating types
        real floating types
            float, double, long double
        complex types
            float _Complex, double _Complex, long double _Complex
standard integer types
    standard sίgned integer types
    standard unsίgned integer types
extended integer types
    extended sίgned integer types
    extended unsίgned integer types
character types
    char, signed char, unsigned char
real types
    integer types
        char
        sίgned integer types
            standard sίgned integer types
                signed char, short int, int, long int, long long int
            extended sίgned integer types
        unsίgned integer types
            standard unsίgned integer types
                _Bool, unsigned char, unsigned short int, unsigned int,
                unsigned long int, unsigned long long int
            extended unsίgned integer types
        enumeration  types
    real floating types
        float, double, long double
scalar types
    arithmetic types
        integer types
            char
            sίgned integer types
                standard sίgned integer types
                    signed char, short int, int, long int, long long int
                extended sίgned integer types
            unsίgned integer types
                standard unsίgned integer types
                    _Bool, unsigned char, unsigned short int, unsigned int,
                    unsigned long int, unsigned long long int
                extended unsίgned integer types
            enumeration  types
        floating types
            real floating types
                float, double, long double
            complex types
                float _Complex, double _Complex, long double _Complex
    pointer types
derived types
    array types
    structure types
    unίon types
    function types
    pointer types
    atomic types
aggregate types
    array type
    structure type
derived declarator types
    array type
    structure type
    pointer type

Now I need to reduce the structure (ideally to a single tree) or find a more tricky way to represent the relations. I would like to came out with a nice cheet-sheet for the C11 typing system. Any ideas?

解决方案

The cluttered structure of C11 types resulting from the second step of the question can be simplified by removal/reduction of less important nodes and delegating some redundant/subsidiary information to be presented by other means.

I propose the following five-step algorithm for that:

  1. Removal of all extended integer types (strictly conforming implementation assumed);
  2. Reduction of the standard integer types (as they do not partition types any more);
  3. Grouping the structure:

    1. A scalar types vs aggregate types pair of sub-trees (represented as a tree),
    2. A basic types vs derived types pair of sub-trees (represented by coloured regions),
    3. real types and derived declarator types (represented as stroked sub-regions of these),
    4. character types (represented with different text colour);

  4. Application of an off-standard production: object types = scalar types + aggregate types;
  5. Supplementing the object types of missing union types and atomic types.

The resulting C11 type system summary looks as follows:

The grey stroke/areas are introduced to increase readability of the tree.

The type summary does not include the concept of "type declaration completeness" because it is a state, observed at a particular point within a translation unit. At run-time, all objects and functions are instances of a complete type. The void type is an exception but, as a no-type (or any-type in case of a pointer), it is intentionally excluded from the diagram.

The const, volatile, restrict and _Atomic are type qualifiers which, contrary to type specifiers for the derived types, cannot be applied recursively. Any combination of these may prepend any type definition (as long as it makes sense). Thus, including them in the diagram would complicate it, while not introducing any suitable information. The apparent exception makes the _Atomic (type) construct, which is taken into account as being a type specifier for the atomic type – one of the derived types listed in the C11 standard.

这篇关于了解C11类型层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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