Stringizing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ravi

    Stringizing

    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

  • Arthur J. O'Dwyer

    #2
    Re: Stringizing


    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

    Comment

    Working...