By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,124 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,124 IT Pros & Developers. It's quick & easy.

maintaining a build# with preprocessor

P: n/a
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?

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 23 Jul 2003 20:43:31 GMT, shea martin <sa******@telus.net>
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

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.