Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!zaphod.mps.ohio-state.edu!samsung!uunet!mcsun!ukc!mucs!logitek!grep!frank From: frank@grep.co.uk (Frank Wales) Newsgroups: comp.lang.c Subject: Embedding macro values in strings Message-ID: <1991Jan10.200806.12745@grep.co.uk> Date: 10 Jan 91 20:08:06 GMT Reply-To: frank@grep.co.uk (Frank Wales) Organization: Grep Limited, LEEDS, UK Lines: 30 Is it possible to write a macro such that the value of one of its parameters, which is derived from another macro, is embedded in a string after pre-processing (and if so, how)? For example, suppose I have foo(__LINE__); in my source, and I want that to expand to bar("Line n"); where n is substituted with the actual value of __LINE__ at that point. Trying #define foo(n) bar("Line "#n) and invoking as foo(10); yields bar("Line 10"); , whereas foo(__LINE__); yields bar("Line __LINE__"); . The zero-parameter alternative version #define foo() bar("Line "#__LINE__) is illegal. Some time playing and reading section A12 of K&RII has been unfruitful. I get the impression I'm being defeated by the sequencing of pre-processor phases, but I'd like to be sure that what I'm attempting is impossible before resorting to other means to achieve what I want. [All this is under MSC 5 under SCO Unix, a supposed ANSI compiler. I'd much prefer an ANSI C solution to a Classic C one. Also, for this problem, gcc's pre-processor would be an awkward choice. Thanks in advance, etc..] -- Frank Wales, Grep Limited, [frank@grep.co.uk<->uunet!grep!frank] Kirkfields Business Centre, Kirk Lane, LEEDS, UK, LS19 7LX. (+44) 532 500303