Stringizing

Discussion in 'C Programming' started by Ravi, Nov 1, 2006.

  1. Ravi

    Ravi Guest

    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
    Ravi, Nov 1, 2006
    #1
    1. Advertising

  2. 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
    Arthur J. O'Dwyer, Nov 1, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton

    Template Stringizing-How should it work?

    Steven T. Hatton, Sep 10, 2004, in forum: C++
    Replies:
    2
    Views:
    1,180
    Steven T. Hatton
    Sep 10, 2004
  2. Siemel Naran

    syntax of stringizing macro

    Siemel Naran, Nov 6, 2004, in forum: C++
    Replies:
    8
    Views:
    1,873
    Old Wolf
    Nov 9, 2004
  3. Henry Townsend

    stringizing a hex value in the preprocessor

    Henry Townsend, Dec 2, 2005, in forum: C Programming
    Replies:
    14
    Views:
    783
  4. Peter Nilsson
    Replies:
    1
    Views:
    469
    James Antill
    Jun 27, 2007
  5. Replies:
    2
    Views:
    374
Loading...

Share This Page