简体   繁体   English

为什么 c++ 预处理文件中仍然存在 #line 预处理器指令?

[英]Why there is still #line preprocessor directive present in a c++ preprocessed file?

I know that the job of a preprocessor is to handle all preprocessor directives of a c++ program and ready the code for compiling.我知道预处理器的工作是处理 c++ 程序的所有预处理器指令并准备好编译代码。 But I have found #line directives are present in almost all preprocessed files.但我发现几乎所有预处理文件中都存在#line 指令。 How compiler understand a preprocessor directive while compiling the code?编译器在编译代码时如何理解预处理器指令?

Why there is still #line preprocessor directive present in a c++ preprocessed file?为什么 c++ 预处理文件中仍然存在 #line 预处理器指令?

Because the compiler needs information about the lines where the code used to be before the pre-processor expanded the directives.因为编译器需要有关在预处理器扩展指令之前代码所在的行的信息。 That information is used for diagnostic messages that report the exact file, line and column where the error is located.该信息用于报告错误所在的确切文件、行和列的诊断消息。

How compiler understand a preprocessor directive while compiling the code?编译器在编译代码时如何理解预处理器指令?

I'm not sure whether #line is technically a pre-processor directive or not.我不确定#line在技术上是否是预处理器指令。 But the compiler understands it for the same reason it understands anything: The smart people who implemented the compiler made it work.但是编译器理解它的原因与它理解任何东西一样:实现编译器的聪明人让它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM