Macro problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rag84dec
    New Member
    • Mar 2007
    • 100

    #1

    Macro problem

    Hi
    I have a Macro defined in one header file say "xyx.h"
    say
    Code:
    #ifdef UNREL
      #define PURPOSE            "I am learning"
      #define TIME        "14"
    #else
      #define PURPOSE                        "Me"
      #define TIME         "14"
    #endif
    in another file say "abc.cpp" i want to use the PURPOSE macro which gives "I am learning"
    What should i do??.....i tried this
    In "abc.cpp" i defined #define UNREL
    then
    [code]
    #ifdef UNREL
    string s=PURPOSE
    #endif
    [/code/

    But the value "I am learning" is not coming......

    PLease help
  • riteshsingh81
    New Member
    • Jul 2007
    • 2

    #2
    Originally posted by rag84dec
    Hi
    I have a Macro defined in one header file say "xyx.h"
    say
    Code:
    #ifdef UNREL
      #define PURPOSE            "I am learning"
      #define TIME        "14"
    #else
      #define PURPOSE                        "Me"
      #define TIME         "14"
    #endif
    in another file say "abc.cpp" i want to use the PURPOSE macro which gives "I am learning"
    What should i do??.....i tried this
    In "abc.cpp" i defined #define UNREL
    then
    [code]
    #ifdef UNREL
    string s=PURPOSE
    #endif
    [/code/

    But the value "I am learning" is not coming......

    PLease help

    >>>>>>>>>
    In your abc.c , before including "xyz.h" use #define UNREL .

    Comment

    • riteshsingh81
      New Member
      • Jul 2007
      • 2

      #3
      Originally posted by rag84dec
      Hi
      I have a Macro defined in one header file say "xyx.h"
      say
      Code:
      #ifdef UNREL
        #define PURPOSE            "I am learning"
        #define TIME        "14"
      #else
        #define PURPOSE                        "Me"
        #define TIME         "14"
      #endif
      in another file say "abc.cpp" i want to use the PURPOSE macro which gives "I am learning"
      What should i do??.....i tried this
      In "abc.cpp" i defined #define UNREL
      then
      [code]
      #ifdef UNREL
      string s=PURPOSE
      #endif
      [/code/

      But the value "I am learning" is not coming......

      PLease help

      >>>>>>>>>
      In your abc.c , before including "xyz.h" use #define UNREL .

      Comment

      • pntkiran
        New Member
        • Jun 2007
        • 16

        #4
        Originally posted by riteshsingh81
        >>>>>>>>>
        In your abc.c , before including "xyz.h" use #define UNREL .
        Hi rag84dec,
        Sample code for your question.
        That will solve your problem.

        Code:
        #define UNREL
        #include "xyz.h"
        #include <iostream>
        using namespace std;
        int main() {
        
        cout << PURPOSE<<endl;
        }
        Regards,
        Kiran Parmar

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by pntkiran
          #define UNREL
          #include "xyz.h"
          #include <iostream>
          using namespace std;
          int main() {

          cout << PURPOSE<<endl;
          }
          I recommend the #define UNREL be used as a command line define when you execute the compiler:

          cl myprog.cpp -DUNREL

          Failing that, put it in a header file of its own and include the header file. You have to avoid a situation where you need to change the source code to chnage the #define since you need to do this in every source file.

          Comment

          Working...