You cannot do this with __DATE__
because it expands to a string constant, and string constants cannot be used in #if
. Also, setting a fixed date is a bad idea, because you may need to make bug fixes in an older version, which should preserve backward compatibility.
(Do you really need to give up backward compatibility? If these are just three lines of code, consider keeping them forever. Your customers will not thank you for βforcing them to be updated.β)
A good way to do this is through a version control system. You must maintain a branch for each version, so write your code as follows:
#ifdef BACKWARD_COMPAT_VERSION_1_0 compatibility code here #endif
and then modify the Makefile only in the release branches, including -DBACKWARD_COMPAT_VERSION_1_0
in your CFLAGS.
source share