#pragma macro

Ken Lerman lerman at stpstn.UUCP
Wed Jun 27 23:35:31 AEST 1990


In article <1990Jun26.145937.27988 at csrd.uiuc.edu> pommerel at sp14.csrd.uiuc.edu (Claude Pommerell) writes:
...[deleted]...
>I am writing portable ANSI C code, but at some points I need to insert
>pragmas to use vectorization facilities of the compiler effectively.
>
>I would like to define a macro
>	#define _DIR_(p1,p2) #pragma thisdir(p1,p2)
>I tried the following variants:
...[deleted]...
>
>7. I use the same idea as in variant 5, but run the preprocessing phase
>   twice, defining
>	   #define _DIR_(p1,p2) _HASH_ pragma thisdir(p1,p2)
>   and calling
>	   _DIR_(arg1,arg2)
>   and compiling
>	   cc -D_HASH_=# -I. -P FILE.c
>	   cc -c FILE.i
...[deleted]...
>
>Does anybody know a variant that works and is conform with the ANSI C
>standard, but more elegant than the double preprocessing in variant 7 ?
>
>						Claude Pommerell
>						pommy at iis.ethz.ch
>					    or  pommerel at csrd.uiuc.edu


As far as I can determine, there is no way to do this in ANSI C.

Your solution, (7.) is not ANSI C, because it relies on the fact that
your compiler lets you run something through the preprocessor and get
at the output.

A -- There is no ANSI requirement that requires the ability to get at
the output from the cpp.

B -- Even if your compiler does have such output, there is no
requirement that the output after preprocessing is a legal C program.
In fact, I've seen at least two compilers where the output of cpp
(after including the vendor's include files) is acceptable to the
vendor's C compiler, but not to other (conforming) compilers.


Unfortunately, ANSI C (also K&R C) is very weak as far as macros are
concerned.  It would be nice to be able to define macros within
macros, ...

I've heard that m4 does a decent job as a macro processor (but haven't
used it).  If you want to be portable, I think you'll have to add
another tool to your chain.

Ken



More information about the Comp.std.c mailing list