macro function

This is a discussion on macro function within the C Programming forums, part of the General Programming Boards category; Hi. I have a Makefile with following definition: Code: CFLAGS += -DSET_WD=ENABLE And in my header file, I want to ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    20

    macro function

    Hi.

    I have a Makefile with following definition:

    Code:
    CFLAGS += -DSET_WD=ENABLE
    And in my header file, I want to have a macro funtion that determines if the SET_WD is set to ENABLE or DISABLE. How can I do that?
    And if not ENABLE, i want to undefine SET_WD.

    I guess i need something like this:
    Code:
    #define(SET_WD) ((SET_WD) != ("ENABLE"))
    #undef SET_WD
    Is it possible?
    Thanks
    Indy

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    #if SET_WD==ENABLE
    ...
    #endif
    perhaps?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    20
    No, It didn't work. I tried:

    Code:
    #if SET_WD!=ENABLE
    #undef SET_WD
    #endif
    Indy

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Before I posted, I actually tried the concept on my local machine, and the #error I stuck inside the #if came out. What error or other "doesn't work" do you get in your case?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,662
    You can only do this is ENABLE is also a #define'd macro, preferably with a value.

    Code:
    #define ENABLE 1
    #if defined(SET_WD) && defined(ENABLE)  && SET_WD != ENABLE
    #undef SET_WD
    #endif
    It would be easier to play with if you makefile simply did
    Code:
    CFLAGS += -DSET_WD=1
    and then all you'd need to do would be
    Code:
    #if defined(SET_WD) && !SET_WD
    #undef SET_WD
    #endif

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    73
    the code can be

    Code:
    #define ENABLE 1
    #if defined (SET_WD)
    #if SET_WD==1
    #undef SET_WD
    #endif
    #endif
    if u replace ENABLE with a numeric then it would be simpler...

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    20
    Ah yeah, ofcourse.
    Thanks grumpy, I used your first suggestion and it works like a charm. I wanted a proper logic so I set the define ENABLE to 1. Makes more sense from the outside.

    Thanks ye all.

    Indy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21