Tom,
Excellent suggestions! It never occurred to me that it
might be possible to define those operators in a preprocessor
that didn't support them natively. Thanks!
-Neil
On Tue, 2013-04-09 at 12:05 -0400, Tom Clune wrote:
> Neil,
>
>
> You may not like my approach, but I've been able to produce the
> desired functionality without explicitly using CPP - even for NAG.
> More long winded than directly using (#) or (##), but at least
> reasonably portable:
>
>
> First, I pass a CPP token on the command line to indicate which
> stringify mechanism to use, and then I #include some conditional
> logic:
>
>
> ! file: stringify.h
> #ifdef STRINGIFY_USE_OPERATOR
> #define TO_STRING(name) #name
> #else
> #define TO_STRING(name) "name"
> #endif
>
>
> So with ifort, I pass "-DSTRINGIFY_USE_OPERATOR" and for the others I
> do nothing. Example code:
>
>
> #include <stringify.h>
> #define REFECTION(name) TO_STRING(name), name
> …
> call suite%addTest(REFLECTION(methodA))
>
>
>
>
>
>
> I do a similar trick for concatenation (##):
>
>
> #ifdef HAS_CONCATENATION_OPERATOR
> #define CONCATENATE(a,b) a ## b
> #else
> #define IDENTITY(x) x
> #define CONCATENATE(a,b) IDENTITY(a)IDENTITY(b)
> #endif
>
>
>
>
> Probably there are compilers out there for which these won't work, but
> not in my development universe.
>
>
> Cheers,
>
>
> - Tom
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Apr 9, 2013, at 10:07 AM, Neil Carlson <[log in to unmask]>
> wrote:
>
> > Has there been any effort in the standardization committee to add
> > the stringify (#)
> > and concatenation (##) operators to the Fortran preprocessor
> > specification?
> >
> >
> > These are perhaps a fringe capability, but useful and with no
> > substitute in some
> > circumstances. I've long wanted # to be able to print the condition
> > in assertions,
> > and have just encountered a situation that calls for ##.
> >
> >
> > Intel's fpp support these; gfortran and NAG do not. I don't know
> > what other
> > compilers do. Or do most people just use the C preprocessor (I'm
> > assuming
> > # and ##, if not part of the standard, are more universally
> > supported there) and
> > cope with the Fortran-ignorant issues it introduces?
> >
> >
> > -Neil
>
> Thomas Clune, Ph. D. <[log in to unmask]>
> Chief, Software Systems Support Office Code 610.3
> NASA GSFC 301-286-4635
> MS 610.8 B33-C128 <http://ssso.gsfc.nasa.gov>
> Greenbelt, MD 20771
>
>
>
>
>
>
>
>
>
|