c++ - 在 C 和 C++ 中, "#"是什么意思?

我很好奇,在 C/C++ 中,# 是什么意思?

例如,#if。它叫做“hashtag if”吗?

最佳答案

源代码中以#if 开头的行称为preprocessor directive如今。在 The C Programming Language ("K&R")1 一书中,它被称为“编译器控制线”。

#这个符号本身好像没有什么特别的名字。例如,documentation for the gcc compiler只是称它为“#”:

Preprocessing directives are lines in your program that start with ‘#’. Whitespace is allowed before and after the ‘#’. The ‘#’ is followed by an identifier, the directive name. It specifies the operation to perform. Directives are commonly referred to as ‘#name’ where name is the directive name. For example, ‘#define’ is the directive that defines a macro.

K&R 书中也只是称其为“#”:

Lines beginning with # communicate with this preprocessor.


1 丹尼斯·里奇,布赖恩·科尼汉; C 程序设计语言,第 1 版(1978 年); p. 207

https://stackoverflow.com/questions/66548702/

相关文章:

regex - 为电话号码编写正则表达式

r - 合并和删除*文件之间的冗余行

flutter - 为什么我们应该在 dart 中使用 static 关键字代替抽象?

github - 如何在两个句子之间添加 Git Readme 中的 Tab 空格?

database - 使用golang从postgres中的csv批量插入而不使用for循环

python - 如何在 Python 中将月份名称生成为列表?

javascript - typescript :为什么我们不能为泛型类型分配默认值?

git - 使用 git rev-parse 的错误提交哈希

python - 在 Python 中获取 Windows 版本

c++ - 如果 new 运算符失败,是否可以将指针设置为 null?