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
Function-like macro definition: An identifier followed by a parameter list in parentheses and the replacement tokens. The parameters are imbedded in the replacement code. White space cannot separate the identifier (which is the name of the macro) and the left parenthesis of the parameter list.
(2) However, you cannot define a macro of a macro like #define INCLUDE #define STDH include <stdio. h> .
Function-like macros can take arguments, just like true functions. To define a macro that uses arguments, you insert parameters between the pair of parentheses in the macro definition that make the macro function-like. The parameters must be valid C identifiers, separated by commas and optionally whitespace.
The first form of the #define directive is called an object-like macro. The second form is called a function-like macro. This directive cancels a previous definition of the identifier by #define .
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)=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With