C 语言中一些非常用知识点 备忘录

本文探讨了C语言中的一些高级特性,包括指定初始化、声明位置的灵活性、标签作用域、不完整类型、限定类型等,并通过具体示例进行了解释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在看一些C语言资料时,总是碰到一些非常见的知识点,看过就忘,这里把他们记录下来。

7. ----> 什么是Designated initializers for aggregate types (C only),看了IBM的解释更易懂,

Designated initializers, a C99 feature, aresupported for aggregate types, including arrays, structures, and unions. Adesignated initializer, ordesignator, points outa particular element to be initialized. Adesignatorlist is a comma-separated list of one or more designators. A designatorlist followed by an equal sign constitutes adesignation.

  • Elements within an aggregate can be initialized in any order.
  • The initializer list can omit elements that are declared anywhere in theaggregate, rather than only at the end.Elements that areomitted are initialized as if they are static objects: arithmetic types areinitialized to 0; pointers are initialized to NULL.
  • Where inconsistent or incomplete bracketing of initializers for multi-dimensionalarrays or nested aggregates may be difficult to understand, designators canmore clearly identify the element or member to be initialized.
下面举例:

struct xyz {
       int a;
       int b;
       int c;
       } klm = { .a = 99, .c = 100 };
int aa[4] = { [2] = 3, [1] = 6 };
static short grid[3] [4] = { [0][0]=8,[0][3]=1,
                             [2][0]=9, [2][1]=3,
                             [2][2]=1, [2][3]=1 };


6.---->C99 permits declarations anywhere within a block. Previous Versions of C permitted them only before the first statment. 参考(C语言参考手册) chapter 4.3

5.----> Statement labels have function scope. 意思就是说用于goto 语句的标号的作用范围是一个函数内。-reference 《C A reference manual》chapter:4.2.1;8.10


4.---->什么是 incomplete type?

  如果有如下定义:

  structure foo;

  structure foo *pFoo;

then the expression  *pFoo is an experession with incomplete type,because the type srtucture foo have not been fully defined.

3.----> 什么是 qualified type,什么是 fully qualified type?


2.---->The C99 function specifier(inline) can appear only on function declarations. -----reference 《C A reference manual》(C语言参考手册) chapter 4.1


1.---->声明一个东西时(一个变量,一个类型,一个函数等),我们需要declaration-specifiers,总共有如下四种specifiers: 参考(C语言参考手册) chapter 4

storage-class-specifier,   type-specifier,    type-qualifier,   function-specifier

其中 storage-class-specifier 有:auto, extern,register,static,typedef

其中Type specififiers 主要提供数据类型信息,有 enumeration,floating-point,interger,structure,typedef-name,union,void

其中type qualitifer 主要是提供更多额外的信息,尤其是在accessing objects of the type through lvalues.  有:const,volatile,restrict.


                          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值