##-concatenation

Discussion in 'C Programming' started by Ravi Uday, Apr 12, 2004.

  1. Ravi Uday

    Ravi Uday Guest

    Hi,

    Why is this code not working ?
    It says " 'TestFn_this_is_new_string' : undeclared identifier"

    #define NEW_STR(x) {x##_this_is_new_string }

    struct command
    {
    char *name;
    }cm[10] = {NEW_STR(testFn)} ;


    Thx,
    Ravi
    Ravi Uday, Apr 12, 2004
    #1
    1. Advertising

  2. Ravi Uday <> scribbled the following:
    > Hi,


    > Why is this code not working ?
    > It says " 'TestFn_this_is_new_string' : undeclared identifier"


    > #define NEW_STR(x) {x##_this_is_new_string }


    > struct command
    > {
    > char *name;
    > }cm[10] = {NEW_STR(testFn)} ;


    Perhaps because you haven't declared the variable
    TestFn_this_is_new_string anywhere?

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
    - Guardian in "Jinxter"
    Joona I Palaste, Apr 12, 2004
    #2
    1. Advertising

  3. Ravi Uday <> spoke thus:

    > Why is this code not working ?
    > It says " 'TestFn_this_is_new_string' : undeclared identifier"


    > #define NEW_STR(x) {x##_this_is_new_string }


    > struct command
    > {
    > char *name;
    > }cm[10] = {NEW_STR(testFn)} ;


    Well, after the macro substitution, you get

    struct command
    {
    char *name;
    } cm[10] = {testFn_this_is_new_string} ;

    First, note that the error message you posted has a capital T, while
    the string you're using for the macro argument has a lowercase t. C
    is case-sensitive, so that could be your problem right there. If not,
    it's probably as Joona suggested - you just didn't declare this
    oddly-named variable anywhere.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Apr 12, 2004
    #3
  4. Ravi Uday a écrit :

    > Why is this code not working ?
    > It says " 'TestFn_this_is_new_string' : undeclared identifier"
    >
    > #define NEW_STR(x) {x##_this_is_new_string }


    I think you want this instead:

    #define NEW_STR(x) {#x "_this_is_new_string" }

    The following points can explain why the above code works, but not yours:
    - You forgot the quotes to make a valid literal string.
    - You did not use the '#' to turn an identifier into a literal string.
    - Consecutive literal strings are automatically concatenated, so you do
    not need the ## macro operator.

    > struct command
    > {
    > char *name;
    > }cm[10] = {NEW_STR(testFn)} ;
    >


    --
    Richard
    Richard Delorme, Apr 12, 2004
    #4
    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. Ralf Hildebrandt

    type conversion and concatenation

    Ralf Hildebrandt, Jul 23, 2003, in forum: VHDL
    Replies:
    3
    Views:
    6,681
  2. walala
    Replies:
    3
    Views:
    4,804
    walala
    Sep 18, 2003
  3. bigdipper_gary
    Replies:
    1
    Views:
    927
    Mike Treseler
    Jan 5, 2004
  4. pandora

    vector concatenation

    pandora, Apr 3, 2004, in forum: VHDL
    Replies:
    8
    Views:
    21,801
    vipinlal
    Mar 26, 2010
  5. Chad

    generic concatenation

    Chad, Aug 25, 2004, in forum: VHDL
    Replies:
    4
    Views:
    663
Loading...

Share This Page