Using typeof in function parameter list?

Kevin P. Fleming kpfleming@starnetworks.us
Tue Jan 11 19:23:00 GMT 2005


I'm trying to build some macros that will define some structures, 
forward declare some functions, declare some other functions (including 
function bodies, etc.). I'm running into a problem though...

My macro takes a number of arguments, one of which is a field name in a 
previously defined struct (whose name is also passed to the macro). I 
want to define some functions that accept parameters of the same type as 
this field, so I try to do this:

#define TEST_MACRO(structtype, fieldname) \
struct structtype __dummy; \
static int foo_function(typeof(_dummy.fieldname) param1, 
typeof(_dummy.fieldname) param2);

Unfortunately, this produces "parse error before (" messages. I can use 
typeof lots of other places, but can't seem to use it to define the 
parameters for a function.

I have been successful in using a typedef inside my macro to create a 
new type name for the desired type, and then using that new type name 
for the function parameters, but that method requires that the 
function's real declaration also use the same typedef, which I was 
trying to avoid.

According to the GCC docs, the "typeof" operator is supposed to be able 
to be used anywhere the type name itself could be used... is this a bug?



More information about the Gcc-help mailing list