In our source files we usually have a version string like that:
static const char srcvers[] = \"VERSION/foo.c/1.01/09.0
Declaring the variable as volatile can also help. That's why it is used in the first place, preventing any optimizations by the compiler regarding that variable.
volatile