C preprocessor: bug or intentional deficiency?

Thomas Johnsson johnsson at chalmers.UUCP
Wed Apr 3 16:38:26 AEST 1985


How do I get a C macro to define another macro? Or rather,
the expansion of a macro causes another macro to be defined.
For example,

	#define defineit(d) \
	#define d hello

The call to defineit

	defineit(hi)

would cause the definition

	#define hi hello

to be entered into the C preprocessor translation table.
Except that it does not seem to work (no matter what permutation
of backslashes and hashes I try :-)

It's clearly a very useful thing to be able to do!
Don't be misled by the triviality of my example above;
Consider the following example, which is more in the spirit of
what I'm trying to do:

	#define defnode2(name) \
	#define make_/**/name(a,b) \
		....		   \
	#define is_/**/name(p) \
		....

Thus I want 

	defnode2(banana)

to mean exactly the same as

	#define make_banana(a,b) \
		....		   \
	#define is_banana(p) \
		....

That this does not work, is it a bug in the preprocessor,
or is it just not supposed to work? If so, why not?

-- 
____________________________________________________________
Thomas Johnsson		..decvax!mcvax!enea!chalmers!johnsson
Chalmers University of Technology, Goteborg, Sweden



More information about the Comp.lang.c mailing list