我有一个非常基础的类,将其命名为Basic,几乎用于更大项目中的所有其他文件.在某些情况下,需要调试输出,但在发布模式下,不应该启用它并且是NOOP.
目前,标题中有一个定义,可根据设置打开或关闭makro.关闭时,这肯定是一个NOOP.我想知道,如果我有以下代码,如果编译器(MSVS/gcc)能够优化函数调用,那么它又是一个NOOP.(通过这样做,交换机可以在.cpp中,并且切换将更快,编译/链接时间明智).
--Header--
void printDebug(const Basic* p);
class Basic {
Basic() {
simpleSetupCode;
// this should be a NOOP in release,
// but constructor could be inlined
printDebug(this);
}
};
--Source--
// PRINT_DEBUG defined somewhere else or here
#if PRINT_DEBUG
void printDebug(const Basic* p) {
// Lengthy debug print
}
#else
void printDebug(const Basic* p) {}
#endif
Run Code Online (Sandbox Code Playgroud) 你应该如何使用WebKit的WebView与模态对话框?
[_webView setMainFrameURL:[NSString fromStdString:url]];
[_nsWindow makeKeyAndOrderFront:nil];
return [NSApp runModalForWindow:_nsWindow];
Run Code Online (Sandbox Code Playgroud)
前面的代码仅适用于Mac OS 10.6.使用10.5,这不会导航到指定的URL.没有runModalForWindow,一切正常.