理解 GCC 依赖 pragma 指令

understanding GCC dependency pragma directive

我正在探索 gcc 支持的编译指示,但我只是不明白 manual#pragma GCC dependency 的看法:

#pragma GCC dependency allows you to check the relative dates of the current file and another file. If the other file is more recent than the current file, a warning is issued. This is useful if the current file is derived from the other file, and should be regenerated. The other file is searched for using the normal include search path. Optional trailing text can be used to give more information in the warning message.

任何人都可以用一些最少的代码解释这部分吗?

This is useful if the current file is derived from the other file

如何从其他文件导出当前文件?我可以理解如何从当前文件派生另一个文件,但不能反之亦然

How can the current file be derived from the other file? I can understand how another file can be derived form the current file but not vice versa.

服务的主要情况是程序使用指定的其他文件作为输入创建 C 源文件。 C 源代码由 运行 程序从其他文件导出。假定其他文件中的差异会导致代码生成器程序以不同方式生成 C 文件,至少有一点不同,否则将不会使用有问题的 pragma。

因此,如果指定的其他文件的 last-modification 时间戳比 C 文件的时间戳更新,那么很可能正在编译 C 文件,因为它可能与当前版本不对应另一个文件。相反,应该再次通过 运行 代码生成程序从另一个文件重新生成 C 源代码,从而获得一个全新版本的 C 文件来替换当前版本。当然,新文件的最后修改时间戳比另一个文件的更新,因为另一个文件必须存在才能从中生成新版本的 C 文件。

示例:

有一个经典程序叫lex,其目的是帮助编写处理文本的程序,尤其是编程语言或富数据语言的文本(细节不重要)。该程序的输入文件描述了如何识别和分类该语言的基本单位,称为 "tokens"。如果被解析的语言是 C,则标记将包括语言关键字、数字常量和运算符。 lex 的输入文件通常有几十行。

lex 读取这样一个输入文件并编写一个 C 源文件,定义几个函数和一些实现所需 "scanning" 行为的内部表:读取输入文本并将其分解为标记,它向其调用者报告。此程序生成的 C 源代码通常有几千行长,与小得多的输入文件相比,简而言之解释了为什么 lex 有用。

要构建一个扫描相关语言的程序,需要提供函数(在不同的源文件中)调用由 lex 生成的函数,并将它们与 lex 生成的函数一起编译获取完整的C源程序。假设 lex 输入文件名为 language.l,并且该文件上 运行 lex 的输出名为 language.c。如果我想改变扫描仪功能的行为,那么要做的就是修改(小,简单)language.l 然后 re-run lex 重新生成 language.c.

当我以任何有意义的方式更改 language.l 时,language.c 会过时,直到我通过 re-running [=] 从 language.l 生成它的新版本 lex。如果我编译 language.c 的过时版本,那么结果不会反映 language.l 的当前版本。这通常构成程序构建人员的错误,并且 #pragma GCC dependency 提供了一种机制,用于在这种情况下从编译器中引发警告。