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

unix – gcc条件编译

发布时间:2020-12-15 17:04:00 所属栏目:安全 来源:网络整理
导读:我正在学习条件编译,我认为到目前为止我对此很了解.现在,如果我有代码: #ifdef UMP_TO_FILE //do something here... #endif 我跑: gcc myprogram.c -DUMP_TO_FILE 然后,代码块“//在这里做某事……”被编译.现在,我的问题是: -DUMP_TO_FILE标志究竟是什么
我正在学习条件编译,我认为到目前为止我对此很了解.现在,如果我有代码:
#ifdef UMP_TO_FILE
    //do something here...
 #endif

我跑:

gcc myprogram.c -DUMP_TO_FILE

然后,代码块“//在这里做某事……”被编译.现在,我的问题是:

-DUMP_TO_FILE标志究竟是什么?

我认为标志是“-D”并且它定义了宏“UMP_TO_FILE”,但是我想确定它的结构和“gcc –help”并没有告诉我任何关于这个的信息,也许我不知道如何在互联网上搜索这个!!

非常感谢您分享您的知识!

man gcc的输出包含这个小片段:

-D name

Predefine name as a macro,with definition 1.

-D name=definition

The contents of definition are tokenized and processed as if they appeared during translation phase three in a #define directive. In particular,the definition will be truncated by embedded newline characters.

If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell’s quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.

If you wish to define a function-like macro on the command line,write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells,so you will need to quote the option. With sh and csh,-D'name(args...)=definition' works.

-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options.

因此,选项-DUMP_TO_FILE相当于将#define UMP_TO_FILE行放在源代码中(存在细微差别,但这里不需要覆盖它们).

顺便说一句,我认为这是一种相当糟糕的做法.作者正在执行欺骗,因此它看起来像编译器选项DUMP_TO_FILE而不是预处理器宏.这有点聪明,但它会给那些想知道UMP_TO_FILE实际意味着什么的人带来麻烦.

就个人而言,我宁愿看-DDUMP_TO_FILE和#ifdef DUMP_TO_FILE,因为它的意图更清晰.

(编辑:李大同)

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

    推荐文章
      热点阅读