maintaining a build# with preprocessor

Discussion in 'C++' started by shea martin, Jul 23, 2003.

  1. shea martin

    shea martin Guest

    Is there a way to keep track of a build number within a program?
    Essentially incrementing a #define everytime the program is compiled (at
    link time would be even better, though tougher to implement).

    something like __DATE__ or __TIME__, perhaps __BUILD__?

    i.e.,

    void printVersion() const { cout << "My Program\n(build __BUILD__)\n"; }

    I suppose that the last value inserted for __BUILD__ would have to be
    maintained somewhere.

    Does anyone have a cute solution?
     
    shea martin, Jul 23, 2003
    #1
    1. Advertising

  2. shea martin

    John Dibling Guest

    On Wed, 23 Jul 2003 20:43:31 GMT, shea martin <>
    wrote:

    >Is there a way to keep track of a build number within a program?
    >Essentially incrementing a #define everytime the program is compiled (at
    >link time would be even better, though tougher to implement).
    >
    >something like __DATE__ or __TIME__, perhaps __BUILD__?
    >
    >i.e.,
    >
    >void printVersion() const { cout << "My Program\n(build __BUILD__)\n"; }
    >
    >I suppose that the last value inserted for __BUILD__ would have to be
    >maintained somewhere.
    >
    >Does anyone have a cute solution?


    You most likely need to manually edit the version numbers when you
    need the nuymbers to change yourself. One way to accomplish this
    would be to have some sort of datatype which encapsulates major
    version, minor version, revision, build number, etc data as ints, and
    set them to appropriate values.

    I used to use a 'cute' solution as you so aptly describe, but my
    experience has shown this to be a bad idea. I had set up a build rule
    to execute a program I wrote which went through a specified h file and
    tweaked some value, thereby effectively increasing the build number
    every time I did a compile. Problems arose with the dependancy
    checker, and build numbers increased in a seemingly lawless manner.

    Think about the motivation for even having a build number. It's to
    support debugging & maintennace, most likely. If this is true, you
    really need to have the numbers increase in a predictable, uniform
    way. This process can't be automated; a human with an able brain must
    make the decision to set a version number.

    </dib>

    John Dibling
    email: dib@substitute_my_full_last_name_here.com
    Witty banter omitted for your protection
     
    John Dibling, Jul 23, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vagif Abilov
    Replies:
    2
    Views:
    599
    Vagif Abilov
    Jul 7, 2004
  2. Cronus
    Replies:
    1
    Views:
    717
    Paul Mensonides
    Jul 15, 2004
  3. Pedro Mir
    Replies:
    2
    Views:
    462
    Winista
    Jun 20, 2006
  4. Nicolas Lehuen
    Replies:
    3
    Views:
    748
    Nicolas Lehuen
    Jan 28, 2004
  5. Toon Knapen
    Replies:
    2
    Views:
    381
    Toon Knapen
    May 17, 2006
Loading...

Share This Page