Quoting C names

Ron Natalie <ron> ron at brl-tgr.ARPA
Fri Nov 16 11:46:30 AEST 1984

>      Is there any easy way to quote a C name?
> Here is an example where it might be used:
> #define FUNCNAME foo
> void FUNCNAME()
> {
>     static char *myself = QUOTE(FUNCNAME);
>     printf("(I'm in %s)",myself);
> }
>     Note that only FUNCNAME need be changed in order to change the name of
>  the function.
> -brad

You will note that do to an ambiguity in the C book, most of the
popular C compilers will allow you to do this easily by the following:

	#define	QUOTE(x)	"x"

When we typed all the C puzzles in to verify a compiler for the IBM 370
we found the compiler interpreted the statement in the C book the other
way and wouldn't substitute the x.  The above macro will work on the AT&T
C preprocessor and hence all AT&T compilers as well as BSD.


More information about the Comp.lang.c mailing list