Preprocessor Usage Question

Gary Weimer 253-7796 weimer at garden.ssd.kodak.com
Fri Apr 26 05:37:50 AEST 1991


In article <R7NX11w163w at shark.cs.fau.edu>, terryb.bbs at 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 at ssd.kodak.com ( Gary Weimer )



More information about the Comp.unix.questions mailing list