编写便携式软件 [英] Writing portable software

查看:134
本文介绍了编写便携式软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的C组,


我对编写便携式C非常感兴趣,但我只有GNU,Sparc

和Cygwin来编译。


我发现编写便携式C的最大问题是要包含的标题

。人们知道哪些网站的内容很全面?


例如,MacOSX抱怨< string.h>。对于Solaris,我需要

来包含除< fcntrl.h>之外的其他头文件。获取定义

来改变读/写文件的非阻塞状态。


如果现代之间有明确的指南系统,这将是非常有用的。


TIA。

杰森。

Dear C group,

I''m very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?

For example, MacOSX complained about <string.h>. With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.

If there is a definitive guide between "modern" systems, this would be
very helpful.

TIA.
Jason.

推荐答案

Jason Curl写道:
Jason Curl wrote:
亲爱的C组,

我对编写便携式C非常感兴趣,但我只有GNU,Sparc
和Cygwin才能编译。

我发现编写便携式C的最大问题是要包含的标题。人们知道哪些网站的差异很全面?

例如,MacOSX抱怨< string.h>。对于Solaris,我需要包含除< fcntrl.h>之外的其他头文件。获取定义来改变读/写文件的非阻塞状态。

如果现代之间有明确的指导。系统,这将是非常有帮助的。

TIA。
Jason。
Dear C group,

I''m very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?

For example, MacOSX complained about <string.h>. With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.

If there is a definitive guide between "modern" systems, this would be
very helpful.

TIA.
Jason.




最简单的答案是坚持一些标准,也许最好的

选择是ANSI标准之一。使用gcc,您可以使用

-std =标准选项来定义要使用的标准。


IAn

-

Ian Bell



The simplest answer is to adhere to some standard and perhaps the best
choice is one of the ANSI standards. With gcc you can use the
-std=standard option to define which standard to use.

IAn
--
Ian Bell


Jason Curl< j _ ******** @ motorola.com>写道:
Jason Curl <j_********@motorola.com> wrote:
我对编写可移植的C非常感兴趣,但我只有GNU,Sparc
和Cygwin才能编译。
我发现编写便携式C的最大问题是要包含哪些标题。人们了解哪些网站的差异是全面的?


C标准列出了您可以合理使用的所有包含文件。对于

C89,这些是


< assert.h> < locale.h文件> < stddef.h>

< ctype.h> <文件math.h> < stdio.h>

< errno.h> < SETJMP.H> < stdlib.h>

< float.h> < signal.h中> < string.h>

< limits.h> < STDARG.H> < time.h>


和C99添加以下内容


< complex.h> < iso646.h> < tgmath.h>

< fenv.h> < stdbool.h> < wchar.h>

< inttypes.h> < stdint.h> < wctype.h>

例如,MacOSX抱怨< string.h>。


然后编译器没有标准兼容你没有机会

可以便携地写任何东西。

使用Solaris I需要包含除< fcntrl.h>以外的其他头文件获取定义
以更改读/写文件的非阻塞状态。


标准C不允许你设置非阻塞状态 - 你

必须已经使用了一些非标准功能(比如open()或

fcntl()等)才能做到这一点。

如果现代与现代之间有确切的指南系统,这将是非常有帮助的。
I''m very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
The C standard(s) list all include files that you can protably use. For
C89 these are

<assert.h> <locale.h> <stddef.h>
<ctype.h> <math.h> <stdio.h>
<errno.h> <setjmp.h> <stdlib.h>
<float.h> <signal.h> <string.h>
<limits.h> <stdarg.h> <time.h>

and C99 adds the following

<complex.h> <iso646.h> <tgmath.h>
<fenv.h> <stdbool.h> <wchar.h>
<inttypes.h> <stdint.h> <wctype.h>
For example, MacOSX complained about <string.h>.
Then the compiler isn''t standard compliant and you have no chance
to write anything portably.
With Solaris I needed
to include another header file other than <fcntrl.h> to get definitions
for changing the nonblocking status of reading/writing files.
Standard C doesn''t allow you to set a "non-blocking" status - you
must already be using some non-standard functions (like open() or
fcntl() etc.) to be able to do that.
If there is a definitive guide between "modern" systems, this would be
very helpful.




这不是一个问题,你使用哪个系统,但你必须限制

你自己对C标准的规定。如果您不是指C语言中的便携式

,还有其他标准,因此您可以编写便携式的

程序,例如:就POSIX标准而言,但是你应该在例如
中询问comp.unix.programmer。

问候,Jens

-

\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de

\ __________________________ http://www.toerring.de


2005年3月14日星期一15:30:33 +0100,Jason Curl

< j _ ******** @ motorola.com>写道:
On Mon, 14 Mar 2005 15:30:33 +0100, Jason Curl
<j_********@motorola.com> wrote:
我对编写可移植的C非常感兴趣,但我只能编译GNU,Sparc
和Cygwin。

我发现的是编写便携式C的最大问题是要包含的标题。人们知道哪些网站在他们的差异方面是全面的?
I''m very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.

What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?




这是一个小小的OT,但我找到了GNU Autoconf和Automake宝贵的

这类事情。它没有解决问题,但确实可以更轻松地处理问题。


你找对哪个头文件是对的include是

大问题之一,但它并不是唯一的问题。你可能会发现

一些操作系统没有你需要的所有功能,所以你需要写b $替换(例如Linux已经getopt_long_only,但是FreeBSD

不行。


Roy



It''s a little OT, but I''ve found GNU Autoconf and Automake invaluable
for this sort of thing. It doesn''t solve the problem, but it does
make handling the problem much easier.

You''re right that finding which header files to include is one of the
big problems, but it''s not the only one. You''ll probably find that
some OSes don''t have all the functions that you need, so you need to
write replacements (e.g. Linux has getopt_long_only, but FreeBSD
doesn''t).

Roy


这篇关于编写便携式软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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