473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Change case of string using PreProcessor

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()?

- Murali

Nov 15 '05 #1
3 13383


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

Nov 15 '05 #2
CPA Study Group wrote:
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).


Just a question, but what do programmers normally do with stupid,
repetitive tasks like writing preprocessor code for 40 functions?

Uli

Nov 15 '05 #3
Ulrich Eckhardt <do******@knuut.de> writes:
Just a question, but what do programmers normally do with stupid,
repetitive tasks like writing preprocessor code for 40 functions?


Automate it with a short script and a Makefile rule.
--
"I should killfile you where you stand, worthless human." --Kaz
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
1
by: Richard Holliingsworth | last post by:
Hello: The group has new 'standards' for online forms and I need to change the 'style' of my existing forms (A2002). Can I do this? I can't find a way using the GUI or the properties. ...
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
14
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have seen the following function to convert from a System::String^ to a const wchar_t*. I would like to get a LPCTSTR and AFAIK LPCTSTR is equal to const wchar_t*. Then it should all work right?...
5
by: .rhavin grobert | last post by:
i read that the preproc will parse macros inside a string if they are prefixed with a sharp. so i did.... ________________________- #define MAJORRELEASE 0 #define PATCHLEVEL 7 #ifdef _DEBUG...
0
by: imranabdulaziz | last post by:
Hi all, I am using asp.net2.0 and C# VS2005. I am creating asp.net web server control templates Dynamically . My requirement is such that sp return very no of field( 4 or 5 or 6 …). Now I am...
6
by: DonMatteo | last post by:
Hi there, I am writing a code to print the results for any given project into the corresponding solution directory. Here is my idea //*** CODE***// // In C/C++ properties, Preprocessor,...
25
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.