CPA Study Group wrote:
Is it possible to write a C Preprocessor macro which changes the case
of a string. This will save me time by not having to use awk of write
my own preprocessor. Here is a sample code which I want to work
---------
#ifdef LOWER
#define NORMAL(x) MKLOWER(x)
#else
#define NORMAL(x) MKUPPER(x)
#endif
extern void NORMAL(Foo)(int x,int y);
extern void NORMAL(Bar)(int x,int y);
extern void NORMAL(Baz)(int x,int y);
...
NORMAL(Foo)(5,6);
NORMAL(Bar)(5,7);
NORMAL(Baz)(7,8);
--------
Basically I want to call the external function "foo" or "FOO" depending
on the preprocessor directive. If all I was worried about was just foo,
I could #define Foo as foo or FOO depending on LOWER. But in my case I
will have to do the #defines for Foo, Bar and Baz (in my application I
will have about 30-40 functions).
Basically is there a string version of toupper()?
No, there's not a string version of toupper(). But
that's not what you need, anyhow: you're not trying to
manipulate strings, you're trying to manipulate identifiers.
Or, more precisely, preprocessing tokens. Since the letters
have already "lost their identities" in the process of
becoming preprocessing tokens, I don't think there's much
hope.
One possibility would be to do the case conversions
by hand and choose between them:
#ifdef LOWER
#define NORMAL(uc,lc) lc
#else
#define NORMAL(uc,lc) uc
#endif
extern void NORMAL(FOO,foo)(int x, int y);
However, if you've only got "about 30-40 functions" I think
you'd probably be better off with the more straightforward
#idfef LOWER
#define Foo foo
#define Bar bar
#else
#define Foo FOO
#define Bar BAR
#endif
extern void Foo(int x, int y);
extern void Bar(int x, int y);
"About 30-40 functions" means fewer than 90 lines worth of
typing -- some of which your editor can do for you. Go
for it, I'd say.
By the way, why do you want to do this renaming? Seems
like a pretty strange thing to want to do ...
--
Er*********@sun.com