Newsgroups: comp.unix.questions
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!ispd-newsserver!garden.ssd.kodak.com!weimer
From: weimer@garden.ssd.kodak.com (Gary Weimer (253-7796))
Subject: Re: Preprocessor Usage Question
Message-ID: <1991Apr25.193750.16702@ssd.kodak.com>
Sender: news@ssd.kodak.com
Reply-To: weimer@ssd.kodak.com
Organization: Eastman Kodak Co.; Rochester, NY
References:  <R7NX11w163w@shark.cs.fau.edu>
Date: Thu, 25 Apr 91 19:37:50 GMT


In article <R7NX11w163w@shark.cs.fau.edu>, terryb.bbs@shark.cs.fau.edu
(terry bohning) writes:
|> Here is a preprocessor question:
|> I want to define a macro which will put either "a_" or 
|> "b_" in front of all my function names.  Can it be done.
|> That is, something like:
|> 
|> #define RADIO a         /* #define RADIO a or b */
|> 
|> main() {
|>         RADIO_func1(args);
|>         RADIO_func2(args);
|>         .
|>         .
|> }
|> 
|> Of course, this doesn't work, but I think you see what I would like
|> to do.

Two ways you COULD do it (may or may not be protable, use at your own
risk, etc, etc,...):

EXAMPLE 1
1>
1>#define RADIO(x)	a_/**/x
1>
1>main() {
1>	RADIO(func1)(args);
1>	RADIO(func2)(args);
1>	.
1>	.
1>}

EXAMPLE 2
2>
2)#define RADIO		a
2>
2>main() {
2>	RADIO/**/_func1(args);
2>	RADIO/**/_func2(args);
2>	.
2>	.
2>}

These work (on my system--SunOS) because the preprocessor treats
comments as delimiters and then removes them. This would not work if:

1) The preprocessor replaced comments with white space
2) The preprocessor did not remove comments, and the compiler treated
   them as delimiters or substituted white space.
3) Your preprocessor was released on the second tuesday after the first
   full moon from one month before Mercury reached its zenith in ...

weimer@ssd.kodak.com ( Gary Weimer )
