[lug] Weird 'C' preprocessor behavior

Alan Robertson alanr at unix.sh
Tue May 22 13:51:26 MDT 2001


I clearly don't understand what's going on here...

I want to expand the string MODULE in this string.

Here's what I tried...

#define MODULE foo
 
#define EXPORT2(module, function) module##__LTX__##function
#define EXPORT(function) EXPORT2( MODULE, function)
#define TEST(function) printf("%s %s", MODULE, function)
 
EXPORT(main)
EXPORT2(MODULE, main)
TEST(bar)

The preprocessor output from gcc is:
 
  MODULE__LTX__main
 MODULE__LTX__main
printf("%s %s", foo ,  bar )

So, it appears that the macro MODULE doesn't get expanded when it is
eventually passed to the ## construction - even if it was a parameter to the
macro.  On the other hand, it does get nicely expanded when it is *not* next
to the ## construction...

Does anyone know how to get 'C' to give me the effect I want?

	Thanks!

	-- Alan Robertson
	   alanr at unix.sh



More information about the LUG mailing list