We are currently busy migrating from Visual Studio 2005 to Visual Studio 2010 (using unmanaged C/C++). This means that about half of our developers are already using Visual Studio 2010, while the other half is still using Visual Studio 2005. Recently, I came into a situation where a certain construction can be written in a clean way in Visual Studio 2010, but requires less-clean source code in Visual Studio 2005. Because not all developers have already Visual Studio 2010 on their machine, I have to write the code like this:
#if _MSC_VER >= 1600
// clean version of the source code
#else
// less clean version
// of the source code
// requiring multiple lines of code
// and requiring some dirty static_casts
#endif
Since all developers will migrate to Visual Studio 2010 by the end of this year, I want this code to 'disappear' automatically after a certain moment. Keeping the 'less clean version' in the source code results in unreadable source code in the long-term.
Of course, I know that code doesn't automatically disappear, so I actually want an automatic alarm bell after a certain moment. Something like this:
#if _MSC_VER >= 1600
// clean version of the source code
#else
// less clean version
// of the source code
// requiring multiple lines of code
// and requiring some dirty static_casts
#endif
#if compilation_date is after 1 november 2010
# error "Remove Visual Studio 2005 compatibility code from this file"
#endif
That way, if we forget about this, we are automatically notified of this after 1 november 2010.
This trick probably requires the use of DATE, but since this needs to be handled by the precompiler, you can't perform string-manipulations or use the C date/time functions.
I also considered the alternative idea of just sending myself a delayed mail, but I was wondering if there wasn't a solution that could be built in in the source code.
In case of GNU make
I'd do it like this:
CFLAGS += -DCURDATE=$(shell date +%Y%m%d)
It will add a macro CURDATE
to compiler flags, that contains the current time in YYYYMMDD format.
So in source you could do something like this:
#if CURDATE > 20101101
#error "Do whatever you have to do"
#endif
Can you do something like this in VS?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With