Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!orchid!rbutterworth From: rbutterworth@orchid.UUCP Newsgroups: comp.lang.c Subject: Re: Second question on #define Message-ID: <11570@orchid.waterloo.edu> Date: Thu, 5-Nov-87 09:42:42 EST Article-I.D.: orchid.11570 Posted: Thu Nov 5 09:42:42 1987 Date-Received: Sat, 7-Nov-87 15:51:04 EST References: <10104@brl-adm.ARPA> Organization: U of Waterloo, Ontario Lines: 25 In article <10104@brl-adm.ARPA>, ultra!wayne@ames.arpa (Wayne Hathaway) writes: > I have a large number of manifest constants of > the form > GREATBIGLONGPREFIX_SHORTTHING > I would like to have a macro accept only SHORTTHING as an argument but > use the full constant name in the generated code. I (naively) tried > #define WIDGET(x) printf("%d\n", GREATBIGLONGPREFIX_x) > but of course this didn't work (didn't substitute x). Put the following into your common header file: #if defined(__STDC__) # define JOIN(x)x## #else # define JOIN(x)x #endif Then, you can do things like #define WIDGET(x) printf("%d\n", JOIN(GREATBIGLONGPREFIX_)x) This works on all the cpp implementations I've used. If you find one that it doesn't work for, you only need to add another condition for the definition of JOIN in the header file to make it work the way that that cpp wants it, and you don't have to change any of your source code.