Thread: Export a predefined constant to an application

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    98

    Export a predefined constant to an application

    I am writing a thread migration system in C. And I am not able to make a feature in my package backward compatible, so I am thinking of predefining a constant like MYPACK_VER so that an application of my package can do this:
    #if MYPACK_VER > 3.0
    use the new format of a feature
    #else
    use the old format of a feature
    #endif
    So it is somewhat similiar to what a compiler would do - for example, GCC defines a VERSION macro so that I guess if a C programmer wants to use a feature that is only provided after GCC version 3.4.4, he can enclose that feature with #if VERSION>3.4.4 / #endif.
    How can I do that in my thread migration system?

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    I'll try to answer your question assuming that what you're asking can be rephrazed as:
    I am updating a thread migration system in C, and am not able to make a specific feature in my package backward compatible. I'm thinking of doing this by using a defined constant such as "MYPACK_VER" so that an application using my package can do the following:
    Code:
    #if MYPACK_VER > 3.0
    use the new format of the feature
    #else
    use the old format of the feature
    #endif
    Given this interpretation of your question, the answer is quite simple -- define the symbol MYPACK_VER in the header file for yor package, as in:
    Code:
    #define MYPACK_VER 3.1 /* versions 3.0 and lower do it the old way */
    Applications that depend on the library can then do something like the following:
    Code:
    #include "mypack.h"    /* use the thread migration package */
    #ifndef MYPACK_VER
    #define MYPACK_VER 1 /* If the version is not defined, it's an early version */
    #endif
    ...
    #if MYPACK_VER > 3.0
    use new facility
    #else
    use old facility
    #endif
    Does this help?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. run windows exe
    By munna_dude in forum Linux Programming
    Replies: 3
    Last Post: 10-10-2007, 01:12 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM