Compile time decision...

This is a discussion on Compile time decision... within the C Programming forums, part of the General Programming Boards category; I have two function foo_good and foo_critically_good. Both the function does conceptually the same thing. Meaning, the code (some fixes ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    175

    Compile time decision...

    I have two function foo_good and foo_critically_good. Both the function does conceptually the same thing. Meaning, the code (some fixes in critically_good function) and parameters passed are the same. Only difference is foo_good resides in part of memory that cannot be changed but foo_critically_good can be changed.

    We have set of such functions, e.g foo1_good, foo2_good, foo3_good etc. foox_critically_good may not exits at all the time. Whenever we find problem with foox_good, we code foox_critically_good and wherever the code calls foox_good needs to be replaced by foox_critically_good. This case need to handled with individual functions.

    Code:
    Option I
    Have a macro in header file
    #define foox_critically_good           TRUE or FALSE
    
    #ifdef foox_critically_good
                  #define      foox   foox_critically_good
    #elseif
                 #define      foox   foox_good
    #endif
    Whenever we need critically good, then set the macro to TRUE and build the image again. This solution is compile time solution and this is what we want.

    Is there any better method than this?

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Not that I can think of in C. This is one of the primary purposes for the preprocessor.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    The macro statement
    #ifdef foox_critically_good
    just checks whether the macro is defined or not. So even if you defined it as FALSE, it will return true.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Compile Time Debugging
    By mindtrap in forum C# Programming
    Replies: 4
    Last Post: 09-17-2007, 09:40 AM
  2. Bugging ... Compile Time Error
    By keats in forum C Programming
    Replies: 7
    Last Post: 03-25-2007, 04:54 AM
  3. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 01:43 PM
  4. Replies: 0
    Last Post: 11-29-2002, 09:24 PM
  5. Debugging mode selection during compile time
    By YALINI in forum C Programming
    Replies: 1
    Last Post: 09-03-2001, 09:56 AM

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