GCC使用-D参数定义类似函数的宏 [英] GCC define function-like macros using -D argument

查看:111
本文介绍了GCC使用-D参数定义类似函数的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

我正在尝试将__attribute__从我的 C 代码中删除,然后再将其发送到解析器中.有没有一种方法可以使用-D参数定义类似函数的宏?

I am trying to remove __attribute__ from my C code before I send it into a parser. Is there a way to define function-like macros using the -D argument?

使用头文件的解决方案

#define __attribute__(x)

尝试的解决方案

gcc -E -D__attribute__(x)= testfile.c
gcc -E -D__attribute__(x) testfile.c

推荐答案

从手册页开始

       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.

所以这可以在Unix/Linux shell上使用

So this works on a Unix/Linux shell

gcc -D'__attribute__(x)='

在Windows CMD上,原始表达式有效,因为括号并不特殊:

on Windows CMD the original expression works, since parentheses aren't special:

gcc -D__attribute__(x)=

这篇关于GCC使用-D参数定义类似函数的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆