清单C常数/宏 [英] Listing C Constants/Macros
问题描述
有没有办法使 GNU C预处理器,cpp(或其他工具)列出所有可用宏及其在中给定点的值。 > C 文件?
Is there a way to make the GNU C Preprocessor, cpp (or some other tool) list all available macros and their values at a given point in a C file?
我正在寻找特定于系统的宏,同时移植已经精通Unix的程序并加载稀疏的unix系统文件。
I'm looking for system-specific macros while porting a program that's already unix savvy and loading a sparse bunch of unix system files.
只是想知道是否有比寻找定义更简单的方法。
Just wondering if there's an easier way than going hunting for definitions.
推荐答案
我不知道文件中的某个位置,而是使用:
I don't know about a certain spot in a file, but using:
$ touch emptyfile
$ cpp -dM emptyfile
转储所有默认值。对包含一些 #include
和 #define
行的C文件执行相同的操作也包括所有这些内容。我想您可以将文件截断到您关心的位置,然后执行相同的操作?
Dumps all the default ones. Doing the same for a C file with some #include
and #define
lines in it includes all those as well. I guess you could truncate your file to the spot you care about and then do the same?
从手册页:
-dCHARS
CHARS
是以下一个或多个字符的序列,并且不能为前面加一个空格。其他字符由适当的编译器解释,或保留给以后的GCC版本,因此将被忽略。如果指定行为冲突的字符,则结果是不确定的。
-dCHARS
CHARS
is a sequence of one or more of the following characters, and must not be preceded by a space. Other characters are interpreted by the compiler proper, or reserved for future versions of GCC, and so are silently ignored. If you specify characters whose behavior conflicts, the result is undefined.
M
为预处理器执行期间定义的所有宏(包括预定义的宏)生成#define
指令的列表,而不是正常的输出。这使您可以找到预处理器版本中预定义的内容。假设您没有文件foo.h,则命令
M
Instead of the normal output, generate a list of#define
directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
将显示所有预定义的宏。
will show all the predefined macros.
如果您使用 -dM
而不使用 -E
选项, -dM
被解释为 -fdump-rtl-mach
的同义词。
If you use -dM
without the -E
option, -dM
is interpreted as a synonym for -fdump-rtl-mach
.
D
与 M
相似,但有两个方面:不包括预定义的宏,并且输出两个 #define
指令和预处理结果。两种输出都进入标准输出文件。
D
Like M
except in two respects: it does not include the predefined macros, and it outputs both the #define
directives and the result of preprocessing. Both kinds of output go to the standard output file.
N
与D类似,但仅发出
N
Like D, but emit only the macro names, not their expansions.
I
输出 #include
指令以及预处理结果。
I
Output #include
directives in addition to the result of preprocessing.
这篇关于清单C常数/宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!