C语言可移植性支持 [英] C language portability support

查看:121
本文介绍了C语言可移植性支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


和typdef一样,C是否有进一步的便携性支持?


谢谢,

ASM

Hi All,

Like typdef, does C have further support for portability?

Thanks,
ASM

推荐答案

" asm" < AR ** @ post.com>在消息中写道

news:c8 ************************** @ posting.google.c om ...
"asm" <ar**@post.com> wrote in message
news:c8**************************@posting.google.c om...
大家好,

和typdef一样,C是否进一步支持可移植性?
Hi All,

Like typdef, does C have further support for portability?



是的,C有支持 '为了可移植性,因为它根据定义是一种便携的,与平台无关的语言。

但是,必须遵循语言规则才能获得

实现上述便携性。


-Mike


Yes, C has ''support'' for portablility, in that it
is by definition a portable, platform-independent language.
However, one must follow the language rules in order
to achieve said portability.

-Mike




" ASM" < AR ** @ post.com>写了

"asm" <ar**@post.com> wrote

就像typdef一样,C是否进一步支持可移植性?

Like typdef, does C have further support for portability?



" typedef"是一种对可移植性的支持,因为通常可以通过typedefing

参数在不同平台上与非C库集成。例如,Windows 3.1使用16位WPARAM。和一个32位
LPARAM。当微软升级到Windows 95时,处理器是32位,所以

制作WPARAM是有意义的。 32位。由于typedeffing,

程序员不需要重写代码。


然而这是一个例外。一般来说,你应该使用int来表示

不太可能超过30,000的数字(例如学校里的学生人数),

和长期不能超过数字的数字20亿(例如一所大学的学生人数为b $ b)。然后代码将在任何符合

的系统上运行。


您将在代码中看到条件定义。 #ifdef

SUN_MICROSYSTEMS #define endiannness 1等


再次这很大程度上是一个错误,因为它使程序很难

测试,阅读和维护。但有时候这是必要的,特别是因为C rubtime图书馆有些不足,而且b $ b不支持显示管理。


"typedef" is sort of a support for portability, in that it is often possible
to integrate with non-C libraries on different platforms by typedefing
parameters. For instance, Windows 3.1 used a 16-bit "WPARAM" and a 32-bit
"LPARAM". When Microsoft upgraded to Windows 95, processors were 32 bit, so
it made sense to make the "WPARAM" 32 bits. Because of typedeffing,
programmers didn''t need to rewrite code.

However this is an exception. Generally you should use int for numbers which
are unlikely to go above 30,000 (such as the number of pupils in a school),
and long for numbers unlikely to go above 2 billion (such as the number of
students in a university). Then the code will run acceptably on any
conforming system.

You will quite commonly see conditional defines in code. #ifdef
SUN_MICROSYSTEMS #define endiannness 1 etc.

Again this is largely a mistake, since it makes programs very difficult to
test, to read, and to maintain. However sometimes it is necessary,
particularly because the C rubtime libraies are somewhat deficient, and
provide no support for display management.


" Mike Wahler" < MK ****** @ mkwahler.net>写道:
"Mike Wahler" <mk******@mkwahler.net> wrote:
" asm" < AR ** @ post.com>写道:
"asm" <ar**@post.com> wrote:
与typdef一样,C是否进一步支持可移植性?
Like typdef, does C have further support for portability?



" typedef"只是一种命名任意抽象数据类型的方法。它是
与可移植性本身无关(除了所有C编译器

支持它)。您可能会想到#ifdef你听错了

一些对话。

是的,C对可移动性有支持,因为它根据定义是一个可移植的平台 - 独立语言。


对不起,但C不是*不是一种与平台无关的语言。它在
中明确规定某些操作如

作为签名整数的右移,或者char的签名是

platform具体。同样,C不是一种可移植的语言。


几乎每个C编译器都会通过neccessity *和绝大多数C暴露重要的平台特定的

功能*程序

专门利用这些扩展使它们不可移植。


与Java比较,这是制作非移植Java的唯一方法/>
程序是为了咀嚼疯狂的内存(不同的b / b
平台会在不同的时间出错),或者有竞争条件

(不同的时间将会导致竞争条件以不同方式显示在

中。

但是,必须遵循语言规则才能实现上述可移植性。


"typedef" is just a way of naming an arbitrary abstract data type. It
has nothing to do with portability per se (except that all C compilers
support it). You may be thinking of "#ifdef" which you misheard from
some conversation.
Yes, C has ''support'' for portablility, in that it
is by definition a portable, platform-independent language.
Excuse me, but C is *NOT* a platform-independent language. It
specifically states in the ANSI standard that certain operations such
as the right shift of signed integers, or the signedness of char are
platform specific. By the same token C is not a portable language.

Virtually every C compiler exposes important platform specific
functionality *by neccessity* and the vast majority of C programs
specifically leverage these extensions which makes them non-portable.

Compare this with Java, where the only way to make a non-portable Java
program is to chew through insane amounts of memory (different
platforms will fault at different times), or have a race condition
(different timings will cause the race condition to manifest in
different ways).
However, one must follow the language rules in order to achieve said
portability.




没有现实世界的程序员故意遵循任何规则。这将是一个完全可移植的C程序。人们可能会无意中这样做,而且通常情况下他们的程序是完全无关紧要的。请记住,C语言的真正目的是制作UNIX风格的命令行

实用程序。你试图用这种语言做的其他事情,通过

本身,通常会让你远离可移植性(只需在x86上使用浮动

点,其中doubles根据编译器*版本*,可以进行64或80位的中间计算:
,只需

普通的预期用量。 (< isspace(0x80)>是UB,< int digit =

(char)cdig - ''0'';>不可移动)会驱使你走向平台

depdendence"关于C语言。


-

Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/


这篇关于C语言可移植性支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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