Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Oct 1995 22:37:33 +0100 (MET)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        phk@critter.tfs.com (Poul-Henning Kamp)
Cc:        hackers@freebsd.org
Subject:   Re: cpp question
Message-ID:  <199510262137.WAA29123@uriah.heep.sax.de>
In-Reply-To: <673.814700238@critter.tfs.com> from "Poul-Henning Kamp" at Oct 26, 95 10:37:18 am

next in thread | previous in thread | raw e-mail | index | archive | help
As Poul-Henning Kamp wrote:
> 
> 
> My new testament is at home, can somebody tell me in the meantime:
> 
> What do I write in a macro to make a token a string ?
> 
> I want to do something like this:
> 
> #define FOO(ptr,fmt,name) \
> 	printf("%s =" fmt "\n", XXXX, (ptr)->name)
> 
> What do I need to put at XXXX ? to convert the name to "name" ?

#define FOO(ptr,fmt,name) \
	printf("%s =" fmt "\n", # name, (ptr)->name)

or simpler:

#define FOO(ptr,fmt,name) \
	printf(# name " =" fmt "\n", (ptr)->name)

(ANSI mandates that "foo" "bar" yields the single string "foobar".)

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510262137.WAA29123>