tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

macro expansion and types in <sys/types.h>



I am building a package (samtools if anyone cares) that tries to define some functions with c preprocessor macro expansions.  In doing so it uses type names (e.g., uint16_t) as both part of the function name as well as one of the types within the function definition.  However, in some but not all places the macro expansion leads to extra underscores being prepended, i.e., uint16_t is sometimes expanded as __uint16_t. 

This is clearly a result of lines like the following in <sys/types.h>:

#ifndef uint16_t
typedef __uint16_t      uint16_t;
#define uint16_t        __uint16_t
#endif

The problem is that the extra underscores that are added to the function names do not match function calls elsewhere without them.

Here is a much simplified example.  Running the following through gcc -E

#include <sys/types.h>

#define M0(x) void name_##x() { }
#define M1(x, y) void name_##x(y) { }
#define M2(x) M1(x,x)

M0(uint16_t)
M1(uint16_t,uint16_t)
M2(uint16_t)

yields the following (omitting all the stuff from sys/types.h):

void name_uint16_t() { }
void name_uint16_t(__uint16_t) { }
void name___uint16_t(__uint16_t) { }

I would appreciate some input from the c preprocessor wizards among you regarding how to fix this problem.

Thanks for your help.

Cheers,
Brook



Home | Main Index | Thread Index | Old Index