如何定义在Mac上的xcode中工作的注释宏

发布于 2024-10-09 01:23:01 字数 245 浏览 0 评论 0原文

在调试模式下使用宏注释输入/输出行非常有用。

不幸的是,正常的方法在 Mac Xcode 上不起作用。

我尝试了 / ## / 以及使用两步宏,就像

#define COMMENT SLASH(/)
#define SLASH(s) /##s

我在网上找到的那样。

但两者都不起作用。

您知道如何定义注释宏吗? 谢谢!

it is quite useful to comment in/out lines using a macro for debug mode.

Unfortunately the normal approaches don't work on the Mac Xcode.

I tried / ## / as well as using a two step macro like

#define COMMENT SLASH(/)
#define SLASH(s) /##s

which I also found in the web.

But neither works.

Do you have an idea which way to define a comment macro.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-10-16 01:23:01

为什么不是这个?

#ifdef DEBUG
// Do debug stuff here
NSAssert(...);
#endif

我很好奇你如何/为什么使用注释宏。

Why not this?

#ifdef DEBUG
// Do debug stuff here
NSAssert(...);
#endif

I am curious how / why you would use a comment macro.

哆兒滾 2024-10-16 01:23:01

同样的问题在这里...

答案似乎是我们期望传统的 XCode 使用符合 ISO 的预处理器(请参阅 http://developer.apple.com/library/mac/#documentation/DeveloperTools/gcc-4.2.1/cpp /Traditional-macros.html#Traditional-macros)
似乎可以更改预处理器的选项,但谁知道你会破坏 Apple SDK 的代码中的内容。

我检查了我的代码并更改了对此类宏的使用,以便宏后面不会跟着应该隐藏的代码,而是将代码作为参数传递给宏...
这样代码仍然可读(不会被 #ifdefs 破坏)...
如果你的调试代码包含“,”,它只会变得丑陋

Same Problem here...

The answer seems to be that we expect a traditional while XCode uses a ISO-conform preprocessor (see http://developer.apple.com/library/mac/#documentation/DeveloperTools/gcc-4.2.1/cpp/Traditional-macros.html#Traditional-macros)
There seems to be the possibility to change the options of the preprocessor, but who knows what you will break in the code from the apple SDKs.

I went through my code and changed my uses of such macros so that the macro is not followed by the code that should be hidden, but instead pass the code as parameter to the macro...
This way the code remains readable (not clobbered with #ifdefs)...
It only gets ugly if your debug-code contains ","

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文