便携式C代码 [英] Portable C code

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

问题描述

我只是想知道你是否知道是否可以编译一个完全可移植的C程序?
?我想在Windows上写一个''C''CGI程序,

然后将它上传到我的基于Debian的Plus.Net服务器。

我想写的纯ANSI C,然后我认为有可能写一个

程序,两者都运行良好。话虽如此,肯定(?),它必须为特定平台编译
,除非在运行时有一些

抽象层,就像java一样。无论如何,这可能不是现在我已经考虑过了。

但是我想知道你们和gals的想法是什么?!


干杯,


Kristan

解决方案

>我只是想知道你是否知道是否有可能编译


>完全可移植的C程序?我想在Windows上写一个''C''CGI程序,然后将它上传到我的基于Debian的Plus.Net服务器。



源代码是可移植的。可执行文件不是。很可能

一个操作系统上的可执行文件在另一个操作系统上不被识别为可执行文件,即使它们在实际相同的CPU上运行(

双靴不同操作系统)。即使它是,它可能无法正确运行。


>因为我想编写纯ANSI C,然后我认为可能写一个
程序,两者都运行良好。



在两者上编译它。


>说完了,肯定是(?),它会
必须针对特定平台进行编译,除非在运行时有一些
抽象层,比如java。无论如何,这可能不是现在我可能已经考虑过了。

但是我想知道你们和gals的想法是什么?!


[后续设置为comp.lang.c,因为我不认为微软人员

都是那个对便携性感兴趣]


Kristan Dyson说:


我只是想知道你是否知道是否有可能编译一个

完全可移植的C程序?



当然,这取决于你所说的完全便携。但是它确实有可能拥有一个非常便携的C程序。


什么是不可能的,唉,有一个二进制文件在任何平台上运行

你喜欢什么 - 无论用什么语言写的。


所以你需要在每个平台(或组)上都有一个编译器您希望支持的二进制兼容的

平台。


我想在Windows上编写一个''C''CGI程序,

然后只需将其上传到我的基于Debian的Plus.Net服务器。

因为我想编写纯ANSI C,所以我认为有可能写

a计划,两者都可以正常运行。



好​​吧,用纯​​ANSI C编写它是为了让你可以编译

源代码而无需先自定义它到特定的平台。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)


Kristan Dyson写道:
< blockquote class =post_quotes>
我只是想知道你是否知道是否可以编译一个

完全可移植的C程序?我想在Windows上写一个''C''CGI程序,

然后将它上传到我的基于Debian的Plus.Net服务器。

我想写的纯ANSI C,然后我认为有可能写一个

程序,两者都运行良好。话虽如此,肯定(?),它必须为特定平台编译
,除非在运行时有一些

抽象层,就像java一样。无论如何,这可能不是现在我已经考虑过了。



这取决于CGI程序必须做什么。

如果它可以通过标准C实现其目标,那就去吧。 />
CGI程序通常只从stdin读取,写入

到stdout,这可以用标准的C来完成。

必须注意你如何处理并转换

输入/输出数据。


如果您需要其他功能 - 套接字,数据库访问等等

it不是,但也许你可以找到

的第三方套餐,这些东西至少可以在你想要支持的系统之间移植。


I was just wondering whether you knew whether it is possible to compile a
fully portable C program? I want to write a ''C'' CGI program on Windows,
then just upload it to my Plus.Net Debian-based server.
As I want to write pure ANSI C, then I thought it may be possible to write a
program that would run fine on both. Having said that, surely (?), it would
have to be compiled for specific platforms, unless of course there is some
abstraction layer at runtime, like with java. Anyway, this is probably not
possible now I have thought about it.
But I would love to know what you guys and gals think?!

Cheers,

Kristan

解决方案

>I was just wondering whether you knew whether it is possible to compile a

>fully portable C program? I want to write a ''C'' CGI program on Windows,
then just upload it to my Plus.Net Debian-based server.

Source code is portable. Executables are not. It is quite possible
that an executable on one OS is not recognized as an executable on
another, even if they are running on the actual same CPU (which
dual-boots different OSs). And even if it is, it may not run correctly.

>As I want to write pure ANSI C, then I thought it may be possible to write a
program that would run fine on both.

Compile it on both.

>Having said that, surely (?), it would
have to be compiled for specific platforms, unless of course there is some
abstraction layer at runtime, like with java. Anyway, this is probably not
possible now I have thought about it.
But I would love to know what you guys and gals think?!


[Followups set to comp.lang.c, since I don''t suppose the Microsoft people
are all that interested in portability]

Kristan Dyson said:

I was just wondering whether you knew whether it is possible to compile a
fully portable C program?

That depends on what you mean by "fully portable", of course. But it''s
certainly possible to have a very, very portable C program.

What is not possible, alas, is to have one binary that runs on any platform
you like - no matter what language it''s written in.

So you do need a compiler on each platform (or group of binary-compatible
platforms) that you wish to support.

I want to write a ''C'' CGI program on Windows,
then just upload it to my Plus.Net Debian-based server.
As I want to write pure ANSI C, then I thought it may be possible to write
a program that would run fine on both.

Well, the point of writing it in pure ANSI C is so that you can compile the
source code without first having to customise it to a particular platform.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Kristan Dyson wrote:

I was just wondering whether you knew whether it is possible to compile a
fully portable C program? I want to write a ''C'' CGI program on Windows,
then just upload it to my Plus.Net Debian-based server.
As I want to write pure ANSI C, then I thought it may be possible to write a
program that would run fine on both. Having said that, surely (?), it would
have to be compiled for specific platforms, unless of course there is some
abstraction layer at runtime, like with java. Anyway, this is probably not
possible now I have thought about it.

It depends on what the CGI program must do.
If it can accomplish its goal by standard C, go for it.
CGI programs typically only reads from stdin, writes
to stdout which surly can be done in standard C.
Care must be taken on how you handle and convert
input/output data though.

If you need other features - sockets, database access, etc.
it is not, but perhaps you can find third party packages for
such things that atleast are portable among the systems you
want to support.


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

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