在编译时区分操作系统 [英] Distinguish OS at compile time

查看:83
本文介绍了在编译时区分操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如果WINDOWS

那么我需要写一些像



如果MAC

这样做


任何可以完成工作的宏?它应该是编译器特定的吗?


非常感谢

解决方案

2006年7月15日13 :20:11-0700,JCR < jc *** @ yahoo.comwrote in

comp.lang.c ++:


你好,


我需要写一些像

如果WINDOWS

这样做

如果MAC

do这个


任何可以完成工作的宏?它应该是编译器特定的吗?


非常感谢



查阅相关编译器的文档,或者询问

支持特定编译器的组。这不是C ++语言

问题。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题

comp.lang.c http://c-faq.com/

comp.lang.c ++ http ://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a。 ..FAQ- acllc.html




JCR写道:


我需要写一些像

如果WINDOWS

这样做

如果MAC

这样做



在这种情况下,我建议你写一些类似的东西:

#if defined WINDOWS


//做一件事


#elif定义的MAC


//做的事情两个


#elif定义OS_370


//做三件事


#else


//不支持的操作系统;什么都不做


#endif


任何可以完成工作的宏?



宏本身只是一个文本,它被预处理器替换为另一个文件。要使上述

方案起作用,你必须在编译器的设置中定义WINDOWS,MAC等等。

对于

你的程序的各种配置。在Visual Studio中,使用每配置

项目设置来执行此操作。 (预处理器选项卡。)对于其他

编译器,请参阅您的手册。


它应该是编译器特定的吗?



宏不是特定于编译器的,不是。他们的行为由C和C ++标准定义为
。有关详细信息,请阅读ISO / IEC-14882。

您可以通过网络从ANSI购买副本


30:
http://webstore.ansi.org /ansidocstor...C+14882%2D2003

查看第16章预处理指令。


编译器的详细信息USES宏是特定于编译器的,但是
。阅读编译器手册了解更多信息。

-

干杯,

Robbie Hatley

East Tustin ,美国加利福尼亚州

孤独的狼inj at pac bell dot net

(将[usenet]置于旁路垃圾邮件过滤器中)
http://home.pacbell.net/earnur/

Hello,

I need to write somethign like
if WINDOWS
do that
if MAC
do this

Any Macro that can do the job? Should it be compiler specific?

Many thanks

解决方案

On 15 Jul 2006 13:20:11 -0700, "JCR" <jc***@yahoo.comwrote in
comp.lang.c++:

Hello,

I need to write somethign like
if WINDOWS
do that
if MAC
do this

Any Macro that can do the job? Should it be compiler specific?

Many thanks

Consult the documentation for the compilers involved, or ask in
support groups for the specific compilers. This is not a C++ language
question.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html



JCR wrote:

I need to write somethign like
if WINDOWS
do that
if MAC
do this


In that case, I suggest you write something like:
#if defined WINDOWS

// do thing one

#elif defined MAC

// do thing two

#elif defined OS_370

// do thing three

#else

// unsupported OS; do nothing

#endif

Any Macro that can do the job?

A macro, by itself, is just one piece of text which is
replaced with another by the preprocessor. To get the above
scheme to work, you''ll have to define "WINDOWS", "MAC", etc.
in your compiler''s settings for the various configurations for
your program. In Visual Studio, use the per-configuration
project settings to do this. ("Preprocessor" tab.) For other
compilers, consult your manual.

Should it be compiler specific?

Macros are not compiler specific, no. Their behavior is defined
by the C and C++ standards. For more info, read ISO/IEC-14882.
You can buy a copy from ANSI over the web for


30:
http://webstore.ansi.org/ansidocstor...C+14882%2D2003
Look in chapter 16, "Preprocessing Directives".

Details of how your compiler USES macros are compiler-specific,
though. Read your compiler''s manual for more.
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lone wolf intj at pac bell dot net
(put "[usenet]" in subject to bypass spam filter)
http://home.pacbell.net/earnur/


这篇关于在编译时区分操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆