Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C Preprocessor getting rid of the __align__ and __attribute__

I am working with a primitive C Parser that does not handle the Preprocessor directive.

I can preprocess most of the header with the -E switch without problem.

Lately I found cases when attribute and align are present.

I tried to get rid of them with this tweak:

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

Update:

But without success, example:

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

The above statements is transformed to, with that "1" pending around

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

Who knowzs the correct way to get rid of the __align__ and __attribute__ extensions ?

like image 353
fabrizioM Avatar asked Apr 21 '11 15:04

fabrizioM


2 Answers

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

like image 105
Andy Finkenstadt Avatar answered Sep 20 '22 18:09

Andy Finkenstadt


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

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

will print 1. If you want to explicitly set the macro replacement list to be empty use -DFOO= (or in your case -D__align__(x)=.

like image 43
hkaiser Avatar answered Sep 23 '22 18:09

hkaiser