gpt4 book ai didi

c++ - #警告和宏观评价

转载 作者:可可西里 更新时间:2023-11-01 16:40:07 27 4
gpt4 key购买 nike

我有以下代码:

#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

问题是在打印警告时未评估 LIMIT_DATE。

我在 Google 上搜索过,但还没有找到解决方案。

感谢您的帮助。

最佳答案

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.

所以至少在 gcc 中是不可能的。

根据 MSDN这应该适用于 MSVC,尽管我目前无法访问 Visual Studio 来测试它

关于c++ - #警告和宏观评价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2298387/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com