关于 struct 声明中 self Referential 的说明

在《The C programming language, second edition》的 section A8.3 中,有这么一段话: A structure may not contain a member of incomplete type. Therefore, it is impossible to declare a structure or union containing an instance of itself. However, besides giving a name to the structure or union type, tags allow definition of self-referential structures; a structure or union may contain a pointer to an instance of itself, because pointers to incomplete types may be declared. ...

 陈十一      2023-06-27    1075字   : 3分钟

关于 C 语言里的 specifier 和 qualifier

在C编程中,“specifier”(指示符)和“qualifier”(限定符)是两个具有不同含义的概念: 指示符(Specifier):在C编程中,指示符是用于定义变量或函数的类型和存储类的关键字。指示符包括int、float、char、void、extern、static等。指示符用于指定变量或函数的基本属性。 ...

 陈十一      2023-06-26    584字   : 2分钟

从 ANSI Standart 的角度,解释 const 和 volatile 的区别

当我阅读《The C programming language, second edition》 SECTION A8.2 (page 211) 时看到下面一段话,谈论的是 const 与 volatile 的对象与编译器优化相关的问题。 The const and volatile properties are new with the ANSI Standart. The purpose of const is to announce objects that may be placed in read-only memory, and perhaps to increase opportunities for optimization. The purpose of volatile is to force an implementation to suppress optimization that could otherwise occur. For example, for a machine with memory-mapped input/output, a pointer to a device register might be declared as a pointer to volatile, in order to prevent the compiler from removing apparently redundant references through the pointer. Except that it should diagnose explicit attempts to change const objects, a compiler compiler may ignore these qulifiers. ...

 陈十一      2023-06-18    2189字   : 5分钟

理解和区分 C 语言的 structure 和 union

在C语言中,structure(结构体)和union(联合体)是用于组织和存储不同类型数据的方式。它们有相似之处,但也有一些关键的区别。 Structure(结构体): 结构体是一种用户自定义的数据类型,可以将不同类型的变量组合在一起形成一个逻辑上相关的数据单元。结构体的成员可以是不同的数据类型,每个成员都有自己的名称和内存地址。结构体的各个成员在内存中是按照定义的顺序存储的,每个成员占据自己的内存空间。 ...

 陈十一      2023-06-17    856字   : 2分钟

从底层逻辑去理解 C 语言的枚举类型

快速知道枚举 在C语言中,枚举(enumeration)是一种用户自定义的数据类型,用于定义一组具有离散取值的常量。枚举类型可以帮助程序员提高代码可读性和可维护性,因为它们允许使用有意义的标识符来表示一组相关的常量。 ...

 陈十一      2023-06-12    1930字   : 4分钟