GCC define function-like macros using -D argument

风格不统一 提交于 2019-12-01 14:36:57

问题


Problem

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?

Solution using header file

#define __attribute__(x)

Attempted Solution

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

回答1:


from the man pages

       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.

So this works on a Unix/Linux shell

gcc -D'__attribute__(x)='

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

gcc -D__attribute__(x)=


来源:https://stackoverflow.com/questions/31857559/gcc-define-function-like-macros-using-d-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!