11

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 the warning.

I searched on Google, but didn't found yet the solution.

Thanks for help.

2
  • On GNU? It does in MSVC. Macro's don't expand their macro arguments, and I don't see a way to get this working the way you want.
    – GManNickG
    Feb 19, 2010 at 17:49
  • 1
    For what it's worth, you can just do #define LIMIT_DATE "01-03-2010". I think it's illegal to escape outside a string.
    – GManNickG
    Feb 19, 2010 at 17:55

1 Answer 1

6

From gcc preprocessor documentation

Neither #error nor #warning macro-expands its argument. Internal whitespace sequences are each replaced with a single space. The line must consist of complete tokens. It is wisest to make the argument of these directives be a single string constant; this avoids problems with apostrophes and the like.

So it's not possible at least in gcc.

According to MSDN this should work for MSVC althrough I don't have access to Visual Studio currently to test this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.