#redefine preprocessor macro statement.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ernie.Pasveer@cggveritas.com

    #redefine preprocessor macro statement.

    Hi All,

    Is there a way to create a macro called #redefine that will allow
    redefinition without having to use #ifdef/#undef

    For example, I'd like to do something like this :

    #define THING "apple"
    ... code

    #redefine THING "banana"
    ... code

    #redefine THING "orange"
    ... code


    Instead of :

    #define THING "apple"
    ... code

    #undef THING
    #define THING "banana"
    ... code

    #undef THING
    #define THING "orange"
    ... code




  • user923005

    #2
    Re: #redefine preprocessor macro statement.

    On Apr 14, 1:00 pm, Ernie.Pasv...@c ggveritas.com wrote:
    Hi All,
    >
    Is there a way to create a macro called  #redefine that will allow
    redefinition without having to use #ifdef/#undef
    >
    For example,  I'd like to do something like this :
    >
        #define THING  "apple"
        ... code
    >
        #redefine THING "banana"
        ... code
    >
        #redefine THING "orange"
        ... code
    >
    Instead of :
    >
        #define THING  "apple"
        ... code
    >
       #undef THING
       #define THING "banana"
        ... code
    >
       #undef THING
       #define THING "orange"
       ... code
    void isolating_funct ion(char *thing)
    {
    /* Do stuff here */
    }


    isolating_funct ion("orange");
    isolating_funct ion("banana");
    isolating_funct ion("apple");

    I think that it is good that you cannot do what you want to do. It is
    trouble waiting to happen.

    Comment

    • Kenneth Bull

      #3
      Re: #redefine preprocessor macro statement.

      On Apr 14, 4:00 pm, Ernie.Pasv...@c ggveritas.com wrote:
      Hi All,
      >
      Is there a way to create a macro called  #redefine that will allow
      redefinition without having to use #ifdef/#undef
      >
      For example,  I'd like to do something like this :
      >
          #define THING  "apple"
          ... code
      >
          #redefine THING "banana"
          ... code
      >
          #redefine THING "orange"
          ... code
      >
      just change the #redefine's to #define's

      >
      Instead of :
      >
          #define THING  "apple"
          ... code
      >
         #undef THING
         #define THING "banana"
          ... code
      >
         #undef THING
         #define THING "orange"
         ... code


      You don't need the #undef before reusing the #define.

      Comment

      • Keith Thompson

        #4
        Re: #redefine preprocessor macro statement.

        Kenneth Bull <kenneth.bull@g mail.comwrites:
        On Apr 14, 4:00 pm, Ernie.Pasv...@c ggveritas.com wrote:
        >Is there a way to create a macro called  #redefine that will allow
        >redefinition without having to use #ifdef/#undef
        >>
        >For example,  I'd like to do something like this :
        >>
        >    #define THING  "apple"
        >    ... code
        >>
        >    #redefine THING "banana"
        >    ... code
        >>
        >    #redefine THING "orange"
        >    ... code
        >>
        No, there isn't. A macro expansion cannot include preprocessor
        directives.
        just change the #redefine's to #define's
        [...]
        You don't need the #undef before reusing the #define.
        Yes, you do. C99 6.10.3p2 says:

        An identifier currently defined as an object-like macro shall not
        be redefined by another #define preprocessing directive unless the
        second definition is an object-like macro definition and the two
        replacement lists are identical.

        followed by similar wording for function-like macros.

        I see this was cross-posted to comp.lang.c and comp.lang.c++. I
        assume the rules for C++ are similar, but I'm not certain. It's
        better to post to the newsgroup that covers the language you're
        actually using.

        --
        Keith Thompson (The_Other_Keit h) <kst-u@mib.org>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        Working...