Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Stringizing

Reply
Thread Tools

Stringizing

 
 
Ravi
Guest
Posts: n/a
 
      11-01-2006
Hi,

I have this

#define KB 1
#define KB_AM 33
#define KB_RM 44
#define AM 2
#define RM 3

#define STR_KB 9
#define STR_AM 10
#define STR_RM 11


void map_fn( int config)
{

int temp;

switch(config) {
case KB:
case KB_AM:
case KB_RM:

if (config == KB)
fill_up (... , STR_KB);
else if (config == KB_AM
fill_up (... , STR_KB_AM);
else if (config == KB_RM)
fill_up (... , STR_KB_RM);
break;

case AM:
fill_up (..., STR_AM);
break;
}

How can i have a macro which based on the 'config value' pre-appends
'STR_' to it and
call fill_up() function.
Inside fill_up() it should give appropriate #defined values for
STR_KB/STR_KB_RM/...etc.

TIA
- Ravi

 
Reply With Quote
 
 
 
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      11-01-2006

On Wed, 1 Nov 2006, Ravi wrote:
>
> I have this

[reformatted inline to conserve vertical space, and re-add indentation
omitted by the OP or by his newsreader]

> #define KB 1
> #define KB_AM 33
> #define KB_RM 44
> #define AM 2
> #define RM 3
>
> #define STR_KB 9
> #define STR_AM 10
> #define STR_RM 11
>
>
> void map_fn(int config) {
> int temp;
> switch (config) {
> case KB:
> case KB_AM:
> case KB_RM:
> if (config == KB)
> fill_up(... , STR_KB);
> else if (config == KB_AM
> fill_up(... , STR_KB_AM);
> else if (config == KB_RM)
> fill_up(... , STR_KB_RM);
> break;
> case AM:
> fill_up(..., STR_AM);
> break;
> }
>
> How can i have a macro which based on the 'config value' pre-appends
> 'STR_' to it and
> call fill_up() function.


What's wrong with the straightforward approach?

#define FILLUP(x) fill_up(... , STR_##x)

-Arthur
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any """Anti Stringizing operator #""" babakandme@yahoo.com C++ 2 12-13-2007 10:25 AM
Re: Stringizing escape character tokens, std. or not? Peter Nilsson C Programming 1 06-27-2007 09:55 PM
stringizing a hex value in the preprocessor Henry Townsend C Programming 14 12-05-2005 10:07 AM
syntax of stringizing macro Siemel Naran C++ 8 11-09-2004 12:23 AM
Template Stringizing-How should it work? Steven T. Hatton C++ 2 09-10-2004 01:06 PM



Advertisments