Han*_*ant 78
到处放置:
#ifndef DEBUG
#error Only Debug builds are supported
#endif
Run Code Online (Sandbox Code Playgroud)
Zde*_*lik 12
也许更柔和的东西,但它只是以前的解决方案的复制和粘贴.:-)
#ifdef DEBUG
#pragma message ( "Debug configuration - OK" )
#elif RELEASE
#error "Release configuration - WRONG"
#else
#error "Unknown configuration - DEFINITELY WRONG"
#endif
Run Code Online (Sandbox Code Playgroud)
PS还有另一种方法如何生成警告.创建一个未引用的标签,如
HereIsMyWarning:
Run Code Online (Sandbox Code Playgroud)
并且不要参考它.在编译期间,您将收到类似的警告
1>..\Example.c(71) : warning C4102: 'HereIsMyWarning' : unreferenced label
Run Code Online (Sandbox Code Playgroud)
您可以error为此使用指令。如果DEBUG未定义,以下代码将在编译时抛出错误:
#ifndef DEBUG
#error This is an error message
#endif
Run Code Online (Sandbox Code Playgroud)