Our code has versioning information hardcoded in printf in at least 20 different files like:
printf("Software version v11.2"); This means changing 20 files everytime there is an update.
Instead i wish to use a macro and #include it in a common.h file, such that version update is just changing one macro, that’s all.
I tried something like:
#include <stdio.h>
#define VERSION "v11.2"
int main()
{
printf("Trying to print macro: ", VERSION);
}
But this style of “string””string” works in Java not in C.
Any ideas how to accomplish it?
We will use the gcc for compilation.
NOTE: The macro is also used in some typical *.rc files, where we can’t use a variable, and somewhere these rc files are parsed using SQL query. So we can’t use variables like char ver[]=”v11.2″
Here are two possible solutions.