加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

列出C常量/宏

发布时间:2020-12-16 03:26:20 所属栏目:百科 来源:网络整理
导读:有没有办法使GNU C Preprocessor,cpp(或其他工具)在C文件中的给定点列出所有可用的宏及其值? 我正在寻找系统特定的宏,同时移植一个已经unix精灵的程序,并加载了一大堆unix系统文件. 只是想知道有没有比寻找定义更简单的方法. 解决方法 我不知道一个文件中的
有没有办法使GNU C Preprocessor,cpp(或其他工具)在C文件中的给定点列出所有可用的宏及其值?

我正在寻找系统特定的宏,同时移植一个已经unix精灵的程序,并加载了一大堆unix系统文件.

只是想知道有没有比寻找定义更简单的方法.

解决方法

我不知道一个文件中的某个位置,但是使用:
$touch emptyfile
$cpp -dM emptyfile

转储所有默认的.对于具有一些#include和#define行的C文件也是一样的,它包括所有这些.我想你可以截断你的文件到你关心的地方,然后做同样的事情?

从man page:

-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
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

06001

will show all the predefined macros.

If you use -dM without the -E option,-dM is interpreted as a synonym for -fdump-rtl-mach.

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
Like D,but emit only the macro names,not their expansions.

I
Output #include directives in addition to the result of preprocessing.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读