Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!samsung!uunet!aussie!rex From: rex@aussie.COM (Rex Jaeschke) Newsgroups: comp.std.c Subject: Re: Preprocessor question Message-ID: <55.UUL1.3#5077@aussie.COM> Date: 17 Feb 91 14:04:27 GMT References: Organization: Journal of C Language Translation Lines: 39 > From: ahuttune@niksula.hut.fi (Ari Juhani Huttunen) > > 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." The following works: --------------------------------- #define BLOCK_SIZE 1024 #define STR1(arg) #arg #define STR2(arg) STR1(arg) char *message = "The block size is " STR2(BLOCK_SIZE) " bytes."; #include main() { printf("message = %s\n", message); } You must go through 2 levels of expansion. If you simply use STR1(BLOCK_SIZE) you get `The block size is BLOCK_SIZE bytes.' instead. Rex ---------------------------------------------------------------------------- Rex Jaeschke | Journal of C Language Translation | C Users Journal (703) 860-0091 | 2051 Swans Neck Way | DEC PROFESSIONAL rex@aussie.COM | Reston, Virginia 22091, USA | Programmers Journal ---------------------------------------------------------------------------- Convener of the Numerical C Extensions Group (NCEG) ----------------------------------------------------------------------------