Stringizing

R

Ravi

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
 
A

Arthur J. O'Dwyer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top