c++ - #line 是什么意思?

标签 c++ c-preprocessor preprocessor-directive

以下行是做什么的?

#line 25 "CSSGrammar.y"

那么扩展是什么?

最佳答案

根据标准:

§16.4.3:

A preprocessing directive of the form

# line digit-sequence new-line

causes the implementation to behave as if the following sequence of source lines begins with a source line that has a line number as specified by the digit sequence (interpreted as a decimal integer). If the digit sequence specifies zero or a number greater than 2147483647, the behavior is undefined.

§16.4.4:

A preprocessing directive of the form

# line digit-sequence " s-char-sequenceopt" new-line

sets the presumed line number similarly and changes the presumed name of the source file to be the contents of the character string literal.

§16.4.5:

A preprocessing directive of the form

# line pp-tokens new-line

(that does not match one of the two previous forms) is permitted. The preprocessing tokens after line on the directive are processed just as in normal text (each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens). If the directive resulting after all replacements does not match one of the two previous forms, the behavior is undefined; otherwise, the result is processed as appropriate.

.y 扩展名正是作者选择使用的,也许是为了表明它是一个 YACC 文件(“语法”一词也指出了这一点,尽管这只是一个猜测) .

关于c++ - #line 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152854/

相关文章:

C++ 预处理器 __VA_ARGS__ 参数数量

c++ - 我可以用#if 做什么?

c++ - 预处理器指令

c++ - 是否有任何控制循环展开的预处理器指令?

c++ - 用 defined(X) 定义一个宏

c - C 编译器将 "-DFOO"处理为与 "-DFOO=1"相同的事实上的标准吗?

c++ - 如何对 const vector 进行排序?

c++ - sf::UdpSocket 的发送和接收方法是线程安全的吗?

c++ - GoogleMock 模拟非虚函数

c++ - LNK2019 错误但 Intellisense 工作正常