Stefan Bossbaly
Stefan Bossbaly

Reputation: 6794

GCC define function-like macros using -D argument

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

Upvotes: 31

Views: 13694

Answers (1)

Robert Jacobs
Robert Jacobs

Reputation: 3350

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

Upvotes: 32

Related Questions