Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
173
第11章
声明
声明(
declaration
)决定了一个或多个标识符的意义与属性。
C11
标准引入的
_Static_
assert
声明是一个例外:这些静态断言(
static assert
)并不声明标识符,它只指示编译
器测试一个常量表达式的值是否是非零。由于静态断言的语法特征,它被划分为声明的
一种。
对于其他声明,所声明的标识符可以是对象名、函数名、类型名等,例如枚举常量。对
象和函数的标识符可以有各种各样的类型和范围。在将标识符应用到表达式中之前,编
译器需要知道该标识符的所有特征。因此,每个翻译单元都必须包含所用到的每个标识
符的声明。
可以在任何语句之前放置用于标识
goto
目的地的标签。这些标签(看作标识符)在使用
的同时,即进行了隐式声明。但所有其他标识符在使用之前,都必须显式地声明,不管
是在函数外面,还是在语句块开头。在
C99
标准中,在同一个语句块内,声明甚至可以
出现在语句后面。
在声明标识符之后,就可以在它的作用域内使用该标识符。对象和函数的标识符可以有
文件作用域或块作用域(请参见
1.6.2
节)。
有几个不同种类的声明:
•
只声明结构、联合或枚举的标签,或枚举成员(枚举常量)
•
声明一个或多个对象或函数的标识符
•
typedef
声明,它对已有类型声明新的名称
•
_Static_assert
声明,它指示编译器不通过声明标识符的方式测试一个断言
(
C11
)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207