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版)
266
|
第
15
章
如果
identifier
不是宏名称,则
#ifndef
标识符后面的条件代码被保留。例
15-1
和例
15-2
展示了上述命令的可能使用方式。
15.5 定义行号
编译器会在警告消息、错误消息与调试信息中包含代码所在的行号与所在的源文件名,
并提供给调试工具。你可以在源代码中利用
#line
命令改变编译器默认指定的文件名与
行号信息。
#line
命令的语法如下:
#line
line_number
["
filename
"]
#line
命令的下一行行号会指定为
line_number
。如果该命令也包含可选字符串字面量
"filename"
,那么该编译器会把该字符串名称作为当前源文件名。
line_number
必须是大于
0
的十进制常量。如下例所示:
#line 1200 "primary.c"
包含
#line
命令的那一行代码,也可以包含其他宏。如果包含其他宏,预处理器会先展
开所有宏,然后再执行
#line
命令。但要确保在宏展开后,
#line
命令是正确的。
程序可以利用标准预定义宏
__LINE__
和
__FILE__
来访问当前的行号和文件名设置:
printf( "This message was printed by line %d in the file %s.\n",
__LINE__, __FILE__ );
#line
命令通常用在将
C
源代码作为输出的程序上。通过将对应的输入文件行号放置在
#line
命令
内,程序可以让
C
编译器的错误消息指向源文件中相应的行。
15.6 生成错误消息
无论是否有实际错误, ...
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