#warning and macro assessment

I have the following code:

#define LIMIT_DATE \"01-03-2010\" #ifdef LIMIT_DATE #if _MSC_VER #pragma message ("Warning : this release will expire on " LIMIT_DATE) #elif __GNUC__ #warning ("Warning : this release will expire on " LIMIT_DATE) #endif #endif 

The problem is that LIMIT_DATE is not evaluated when printing a warning.

I searched on Google but could not find a solution.

Thanks for the help.

+7
c ++ macros
source share
1 answer

From the documentation for the gcc preprocessor

Neither #error nor #warning macro expands its argument. internal whitespace sequences are replaced with one space. The string should consist of full tokens. it is wiser to argue these directives should be a single line constant; this avoids problems with apostrophes, etc.

So this is not possible, at least in gcc.

According to MSDN , this should work for MSVC since I don't have access to Visual Studio at this time to verify this

+5
source share

All Articles