首页 文章

了解C11类型层次结构

提问于
浏览
34

我想完全理解C11语言的类型层次结构并以图形方式呈现它(树形图将是完美的) . 该标准没有提供任何关于这个问题的数字 - 有30个点描述了它们之间的各种类型和关系 . 我想画它 .

我的尝试从获取ISO/IEC 9899:201x Committee Draft N1570并从文档的第6.2.5节中提取所有必要的陈述开始 . 然后,我开始以树的形式重新安排知识 . 让我分两步介绍我的工作 .

步骤1:点1-15

提取的知识(6.2.5节规定的 生产环境 点):

  • 1个类型=对象类型函数类型;

  • 4个标准有符号整数类型= signed charshort intintlong intlong long int ;

  • 4个有符号整数类型=标准有符号整数类型扩展有符号整数类型;

  • 6个标准无符号整数类型= _Boolunsigned charunsigned short intunsigned intunsigned long intunsigned long long int ;

  • 6无符号整数类型=标准无符号整数类型扩展无符号整数类型;

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

  • 7扩展整数类型=扩展有符号整数类型扩展无符号整数类型;

  • 10个真实浮动类型= floatdoublelong double ;

  • 11复杂类型= float _Complexdouble _Complexlong double _Complex ;

  • 12浮动类型=真正的浮动类型复杂类型;

  • 14个基本类型= char 有符号整数类型无符号整数类型浮点类型;

  • 15个字符类型= charsigned charunsigned char .

由此产生的结构:

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

第2步:第16-24点

其余的陈述:

  • 16枚举类型;

  • 17整数类型= char 有符号整数类型无符号整数类型枚举类型;

  • 17个实数类型=整数类型实数浮动类型;

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

  • 20个派生类型=数组类型,结构类型,联合类型,函数类型,指针类型,原子类型;

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

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

  • 24派生的声明符类型=数组类型函数类型指针类型 .

最终的C11型系统结构:

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

现在我需要减少结构(理想情况下是单个树)或找到一种更难以表示关系的方法 . 我想为C11打字系统提供一张漂亮的笔记本 . 有任何想法吗?

1 回答

  • 16

    通过删除/减少不太重要的节点并委托一些冗余/辅助信息通过其他方式呈现,可以简化由问题的第二步产生的C11类型的混乱结构 .

    我提出了以下五步算法:

    • 删除所有扩展整数类型(严格遵循假定的实现);

    • 减少标准整数类型(因为它们不再分区类型);

    • 对结构进行分组:

    • 标量类型与聚合类型对子树(表示为树),

    • 基本类型与派生类型的子树对(由彩色区域表示),

    • 实数类型和派生声明符类型(表示为这些类型的描边子区域),

    • 个字符类型(用不同的文字颜色表示);

    • 非标准 生产环境 的应用:对象类型=标量类型聚合类型;

    • 补充缺少的联合类型和原子类型的对象类型 .

    生成的C11类型系统摘要如下所示:

    C11 type hierarchy

    引入灰色笔划/区域以增加树的可读性 .

    类型摘要不包括"type declaration completeness"的概念,因为它是在翻译单元内的特定点观察到的状态 . 在运行时,所有对象和函数都是完整类型的实例 . void 类型是一个例外,但是,作为非类型(或指针的情况下的任何类型),它有意地从图中排除 .

    const ,_ 283101restrict_Atomic 是类型限定符,与派生类型的类型说明符相反,不能递归应用 . 这些的任何组合可以预先添加任何类型定义(只要它是有意义的) . 因此,将它们包含在图表中会使其复杂化,而不会引入任何问题适当的信息 . 明显的异常使 _Atomic (type) 构造被考虑为原子类型的类型说明符 - C11标准中列出的派生类型之一 .

相关问题