Preprocessor question

Doug Gwyn gwyn at smoke.brl.mil
Mon Feb 18 07:11:30 AEST 1991


In article <AHUTTUNE.91Feb16230548 at silver-surfer.hut.fi> ahuttune at niksula.hut.fi (Ari Juhani Huttunen) writes:
>I would like to do the following or something similar:
>#define BLOCK_SIZE 1024
>char *message = "The block size is " # BLOCK_SIZE " bytes.";
>I need the result: "The block size is 1024 bytes."
>I know what I am doing wrong, but HOW should I do it? These alternatives
>are no good:
>	- #define BLOCK_SIZE_STRING "1024"
>	- char *message = "The block size is 1024 bytes.";

#define	STRINGIZE(x)	# x	
#define	PSTRINGIZE(x)	STRINGIZE(x)
...
#define	BLOCK_SIZE	1024
...
char	message[] = "The block size is " PSTRINGIZE(BLOCK_SIZE) " bytes.";



More information about the Comp.std.c mailing list