maintaining a build# with preprocessor

S

shea martin

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?
 
J

John Dibling

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top