C Preprocessor getting rid of __align__ and __attribute__

I work with primitive C Parser, which does not handle the preprocessor directive.

I can pre-process most of the header with the -E switch without any problems.

Recently, I have discovered cases where attributes are present and align .

I tried to get rid of them using this setting:

gcc -D "aligned(ARGS)" \ -D "__align__(ARGS)" \ -D "__attribute__(ARGS)" \ -E /usr/local/include/fancyheader.h 

Update:

But without success, for example:

 struct __attribute__((aligned(16))) long4 { long int x, y, z, w; }; 

The above statements translate to "1" pending

 struct 1 long4 { long int x, y, z, w; }; 

Who knows the right way to get rid of the __align__ and __attribute__ extensions?

+6
source share
3 answers

What happens if you use -D "aligned(ARGS)=" ?

+10
source

The preprocessor assigns a value of 1 all macros defined on the command line, without specifying a replacement list. For example, if you compile with -DFOO:

 std::cout << FOO << std::endl; 

prints 1 . If you want to explicitly indicate that the macro replacement list is empty, use -DFOO= (or, in your case, -D__align__(x)= .

+3
source

How about defining all the built-in and predefined macros with the -U option and then creating new definitions using the -D option?

0
source

Source: https://habr.com/ru/post/886406/


All Articles