By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Stringizing

P: n/a
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

Nov 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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
Nov 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.