I search for a way to print a message or break a compile run if a headerfile is expired, something like:
#ifndef somemagic(__DATE__ , "2014")
#pragma message("ALARM! Someone should check this file!")
#endif
or is there some new template magic?
To be more specific. I got no way to change the compiler chain. The solution has to be part of the source code. A compiler switch or even add a define in a makefile is not an option.
Note: It is a technical question, which (IMHO) deservers a technical answer. Even if may not fit in all situation, there are reasons where such a technic may be handy.
You can use the fact that __DATE__
expands to a string literal, and string literals are constant expressions:
static_assert(
( 1000 * (__DATE__[7] - '0')
+ 100 * (__DATE__[8] - '0')
+ 10 * (__DATE__[9] - '0')
+ (__DATE__[10] - '0')
) != 2014, "It's 2014!"
);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments