ifdef 和索拉里斯
我想在 SunOS 上编译时取消定义变量。因此,我尝试放置
#ifdef SunOS
#undef FOO
#endif
但它不起作用。问题出在#ifdef sunos ?我应该声明它,还是编译器自己做?
问候 S。
I want to undefine variable when compiling on SunOS. Therefore, i tried to put
#ifdef SunOS
#undef FOO
#endif
but it does not work. The problem is in #ifdef sunos ? Should i declarate it, or complier do it by itself ?
regards
S.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的编译器将包含许多预定义的变量。请参阅编译器文档以了解该列表是什么。
如果您试图使一个软件可以在多个(类似 UNIX)平台上构建,请查看 自动配置。它有一点学习曲线,但从长远来看回报非常丰厚。
添加:
此外,您的编译器可能有一种列出预定义宏的方法。例如,使用 gcc,
touch foo.h; cpp -dM foo.h
生成所有 then 的列表,在 OS X 上使用 gcc 时,该列表达到 119 个。但是文档可能会给出该编译器的推荐宏的一些指示(但总的来说,autoconf 仍然是一种更好的技术)。Your compiler will include a number of variables predefined. See your compiler documentation to find out what that list is.
If you're trying to make a piece of software buildable on multiple (unixlike) platforms, then take a look at autoconf. It has a bit of a learning curve, but pays off very handsomely in the long term.
Addition:
Also, your compiler might have a way of listing the predefined macros. For example, using gcc,
touch foo.h; cpp -dM foo.h
produces a list of all of then, which comes to 119 with gcc on OS X. But the documentation will probably give some indication of that compiler's recommended macros for this (but autoconf remains a better technique for this in general).这没有什么问题,
cpp
可以很好地接受该片段。您看到什么问题?There's nothing wrong with that,
cpp
accept that fragment just fine. What's the problem you're seeing?我不知道有哪个 Solaris 编译器可以为您预定义
SunOS
。Sun 编译器在“cc”手册页的
-D
选项说明下列出了它们预定义的宏,包括__sun
和__SunOS_5_10
(对于 uname -r 为“5.10”),但不仅仅是普通的SunOS
。I don't know of any compilers for Solaris that predefine
SunOS
for you.The Sun compilers list the macros they predefine in the 'cc' man page under the
-D
option description, including__sun
and__SunOS_5_10
(for uname -r of "5.10"), but not just plainSunOS
.