Som*_*ent 3 c makefile mupdf ifndef
我正在尝试在MuPDF中启用调试选项.出于某种原因,他们使用了我想要使用的代码#ifndef NDEBUG
并使其#endif
变灰.我在整个图书馆搜索,但找不到任何地方定义的任何NDEBUG痕迹.我已经设法通过添加#undef NDEBUG
标题来解决这个问题,但我想知道是否有更多非侵入性的方法来执行此操作.
那么,你能从makefile中启用"#ifndef /#endif"块吗?
另外,为什么你会使用#ifndef
灰色代码?不应该是#ifdef NDEBUG
吗?
您可以将-DNDEBUG添加到Makefile中的以下3个变量 - CFLAGS,CPPFLAGS和CXXFLAGS以定义NDEBUG.这相当于添加#define NDEBUG
还有其他变化:
-DNBDEBUG=1
Run Code Online (Sandbox Code Playgroud)
相当于
#define NDEBUG 1
Run Code Online (Sandbox Code Playgroud)
并回答为什么有人使用#ifndef代替#ifdef的问题是因为它非常清楚地突出了对原始代码的修改.
例如,请将以下代码视为原始版本:
int a = 123;
int b = 346;
int c = a + b;
Run Code Online (Sandbox Code Playgroud)
而且你需要添加一个宏DO_MULT,它会相乘 - 有两种方法可以做到这一点.
第一个变化:
int a = 123;
int b = 346;
#ifdef DO_MULT
int c = a *b;
#else
int c = a + b;
#endif
Run Code Online (Sandbox Code Playgroud)
第二种变化:
int a = 123;
int b = 346;
#ifndef DO_MULT
int c = a + b;
#else
int c = a *b;
#endif
Run Code Online (Sandbox Code Playgroud)
如果您使用difftools来查看更改 - 第二个变体将比第一个更明显地显示差异.
使用#ifndef的另一个原因是在CATCH-ALL-EXCEPT场景中做了些什么.