C,真的很便携吗? [英] C, really portable?

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

问题描述

C真的很便携吗?道歉,但这可能有点旧吗?


在clc我们经常看到''不便携''的评论,但我想知道如何

便携式C应用程序确实如此。


我不编写便携式C代码 - *不仅*因为,在'C意义上',我

可能做的事情是不可移植的 - 但是因为在过去的x年里,

我已经编写了代码来运行在许多不同的平台上。那些应用程序

必须使用系统调用,使用线程,提供漂亮的UI,。


前提:任何体面复杂的现代应用程序都无法完全编写
标准C中的
[意思是,没有编译器的语言添加''扩展'',

并且仅使用标准库]。或者,如果它是用标准C写的,那么它是'次优的''[并且当然没有一个漂亮的用户界面!]。


结论:虽然语言是可移植的,但应用程序却不是。并且

这就是为什么我们也经常看到''去问别处''这里出现的评论

[完全合理他们当然也是如此]。


无论如何,只是一个想法,我想知道是否有人可以拿出一个柜台来支付
呢?

Is C really portable? And, apologies, but this is possibly a little OT?

In c.l.c we often see ''not portable'' comments, but I wonder just how
portable C apps really are.

I don''t write portable C code - *not only* because, in a ''C sense'', I
probably do things that aren''t portable - but because for the last x years,
I''ve written code to run on a number of different platforms. Those apps
have had to make use of system calls, use threads, present nice UIs, .

Premise: any decently complex modern application cannot be entirely written
in standard C [meaning, the language without compiler added ''extensions'',
and only using the standard libraries]. Or, if it is written in standard C,
then it is ''sub optimal'' [and certainly doesn''t have a nice UI!].

Conclusion: Whilst the language is portable, applications are not. And
that''s why we also often see ''go and ask elsewhere'' comments appearing here
[totally reasonable they are too of course].

Anyway, just a thought, and I wonder if anyone can come up with a counter to
it?

推荐答案

pemo说:
pemo said:
C真的很便携吗?


C不可移动。

C程序并不是非常便携 - 有点,这就是全部。

如果做得好,C库可以*令人惊讶地*便携。


C语言不比英语便携或多或少。

有用的C程序可以编写,可以在很多环境中使用,而且确实我自己写了很多这样的程序。


但是哪里有C真正的分数在于你可以写一整套

的东西,这些东西在任何平台上都很有用,并称之为

库。

在clc中我们经常看到不便携的评论,但我想知道便携式C应用程序是如何实现的。
Is C really portable?
C isn''t portable.
C programs aren''t terribly portable - a bit, that''s all.
C libraries can be *astoundingly* portable, if done properly.

C the language isn''t any more or less portable than English.

Useful C programs can be written which will work in many environments, and
indeed I have written many such myself.

But where C really scores is in the fact that you can write a whole bundle
of stuff that will be useful on any platform whatsoever, and call it a
"library".
In c.l.c we often see ''not portable'' comments, but I wonder just how
portable C apps really are.




如果仔细编写以将其

功能的任何非便携部分抽象为单独的模块,C应用程序可以非常便携。拿出500,000行经过精心编写的代码,其中5,000行是精心隔离的平台相关内容,其余的是

直接ISO C.每次重写那5000个你找到了一个新的平台。

需要大约四个人工周才能进入港口,而不是八个人年。嘿presto,

便携式网络浏览器。 (嗨Borris。)


-

Richard Heathfield

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

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



If carefully written to abstract any non-portable parts of their
functionality into separate modules, C applications can be extraordinarily
portable. Take 500,000 lines of carefully written code, 5,000 of which are
carefully isolated platform-related stuff, and the rest of which is
straight ISO C. Rewrite those 5,000 every time you hit a new platform.
Takes about four man-weeks to port, instead of eight man-years. Hey presto,
portable Web browser. (Hi Borris.)

--
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)


pemo写道:
C真的很便携吗?而且,道歉,但这可能有点旧吗?


C非常便携。

在clc中我们经常看到''不便携''的评论,但我想知道
便携式C应用程序真的是。


大多数应用程序的90%[1]可以用便携式C写,只留下10%你需要实际定制目标。

我不编写可移植的C代码 - *不仅*因为,在'C意义上',我可能会做一些不可移植的东西 - 但是因为最后x年,
我编写的代码可以在许多不同的平台上运行。这些应用程序必须使用系统调用,使用线程,提供良好的UI ,.


所以你在系统特定模块中隔离这些代码片段。

前提:任何体面复杂的现代应用程序都不能完全写成标准
C [意思是,没有编译器的语言添加了''扩展'',
并且只使用标准库]。或者,如果它是用标准C编写的,那么它就是次优[并且肯定没有一个漂亮的用户界面!]。


当然,大部分应用程序都有非标准组件,但

并不意味着大部分代码都必须是非标准的。

结论:虽然语言是可移植的,但应用程序却不是。而且这就是为什么我们也经常看到''去问别处''这里出现的评论
[完全合理他们当然也是如此]。


许多应用程序非常便携,只需要为特定目标定制少量的b $ b b。这可以通过使用多个目标上可用的库来协助系统特定的东西

(例如QT或GTK +)。


我已经为嵌入式系统编写了C,然后我在硅片上调试了一个图形工作站(带有一些包装代码),其中一些代码是

然后在另一个完全不同的平台上使用。


我目前正在处理的代码注定要在Windows,Linux上运行
和AIX(不在该订单),该应用程序以前运行过

其他系统。

无论如何,只是一个想法,我想知道是否有人可以拿出一个柜台来/>它?
Is C really portable? And, apologies, but this is possibly a little OT?
C is very portable.
In c.l.c we often see ''not portable'' comments, but I wonder just how
portable C apps really are.
90%[1] of most apps can be written in portable C leaving only 10% you
have to actually tailor for the target.
I don''t write portable C code - *not only* because, in a ''C sense'', I
probably do things that aren''t portable - but because for the last x years,
I''ve written code to run on a number of different platforms. Those apps
have had to make use of system calls, use threads, present nice UIs, .
So you isolate those pieces of code in a system specific module.
Premise: any decently complex modern application cannot be entirely written
in standard C [meaning, the language without compiler added ''extensions'',
and only using the standard libraries]. Or, if it is written in standard C,
then it is ''sub optimal'' [and certainly doesn''t have a nice UI!].
Certainly the bulk of applications have non-standard components, but
that does not mean the bulk of the code has to be non-standard.
Conclusion: Whilst the language is portable, applications are not. And
that''s why we also often see ''go and ask elsewhere'' comments appearing here
[totally reasonable they are too of course].
Many applications are very portable, requiring just a small amount of
tailoring for specific targets. This can be assisted by using libraries
that are available on multiple targets for the system specific stuff
(e.g. QT or GTK+).

I''ve written C for an embedded system that I then debugged on a silicon
graphics workstation (with some wrapper code) and some of the code was
then used on another completely different platform.

The code I''m currently working on is destined to run on Windows, Linux
and AIX (not in that order), and the application has previously run on
other systems.
Anyway, just a thought, and I wonder if anyone can come up with a counter to
it?




见上文。我们这里的许多人都在研究需要在多个平台上运行的软件,并且在我开始编程之前我们使用了自

以来的技术。模块化和

之类的东西可以保留大部分模块中的所有系统特定的东西。


[1] 75%的统计数据都是在当场

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,它是真实的,我读了它。



See above. Many of us here work on software that is required to run on
multiple platforms, and we use techniques that have been around since
before I started programming to do it. Things like modularisation and
keeping all the system specific stuff out of the bulk of the modules.

[1] 75% of all statistics are made up on the spot
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


pemo写道:
前提:任何体面复杂的现代应用程序都不能完全写成
标准C [意思是,没有编译器的语言添加''扩展'',
并且只使用标准库]。或者,如果它是用标准C编写的,那么它就是''次优''[并且肯定没有一个漂亮的用户界面!]。


嗯...是的,因为您经常需要与操作系统和

环境进行交互。但是每次我开始一个新项目时,我都不会单独重写程序。我拖放库我已经写了

年,只是为程序写了一个新的主文件。


结论:虽然语言是可移植的,但是应用程序是没有。

那就是为什么我们也经常看到''去问别处''这里出现的评论
[完全合理他们当然也是如此]。
<无论如何,只是一个想法,我想知道是否有人可以拿出一个柜台来
它?
Premise: any decently complex modern application cannot be entirely written
in standard C [meaning, the language without compiler added ''extensions'',
and only using the standard libraries]. Or, if it is written in standard C,
then it is ''sub optimal'' [and certainly doesn''t have a nice UI!].

Well... yes since you often have to interact with the OS and
environment. But I don''t re-write programs monolithically every time I
start a new project. I "drag&drop" libraries I''ve written over the
years and just write a new main file for the program.

Conclusion: Whilst the language is portable, applications are not.
And that''s why we also often see ''go and ask elsewhere'' comments appearing here
[totally reasonable they are too of course].

Anyway, just a thought, and I wonder if anyone can come up with a counter to
it?




这将是一个漫长的过程(ish)故事...


在我以前的公司,我已经和那些认为像这样的人一起努力了。我们的产品运行在各种不同的环境中,所有不同的操作系统(一些没有),所有不同的CPU系列和

所有不同的编译器。


产品范围从小型8位PIC到中型8位Z80到大型

16bit 68000到486,一直到现代200Mhz ARM9。但是他们所有人都需要做同样的工作 - 通过串行线获取数据,

处理和路由数据并通过串行线路传输数据
必要时
。毋庸置疑,这种环境鼓励人们继续重新发明轮子。而我的老板,70多岁的工程师,

认为这是自然的做事方式。


我相信C的便携性并且对此设置感到震惊。

特别是重新发明了车轮部件。所以我开始编写

可移植代码,用于简单的东西,如CRC16和base64编码等。

使用#ifdefs选择适当的资源实现

饥饿系统(PIC平均只有20个字节的ram)。然后我转向更加复杂的东西,如Modbus协议引擎。


然后真正的斗争开始了 - 试图说服人们这是

的路要走。我已经赢得了团队成员之间的转换,因为

他们发现能够简单地浏览我的共享文件夹

库来获得他们需要的东西是很好的。慢慢地人们开始感谢修改文件中的错误修复了所有

平台的效果。


更改在编写代码的态度导致了一个巨大的库

的可重用代码。这使我们能够专注于添加新的

功能,并使我们免于依赖单个的b / b
CPU /平台。当我们的竞争对手从68000'转移到PPC时,我们也能够做到这一点。当ARM在嵌入式设备中风靡一时

时,我们也可以将产品转移到它。


所以,我已经编写了代码一直工作从4MHz,8位CPU,20 / b $ b字节RAM到200MHz,32位CPU,128MB RAM和硬盘。

完整的程序显然不是便携式,因为你不能指望

a 1MB程序适合1kB的EEPROM。但我自己编写的代码是可移植的。 main()理想情况下应该是代码中唯一的

非便携部分。



This is going to be a long(ish) story...

At my previous company, I''ve fought hard against people who think like
this. Our products run on a wide variety of different environment, all
with different OSes (some with none), all different CPU families and
all different compilers.

The products range from small 8bit PICs to medium 8bit Z80s to large
16bit 68000 to 486 all the way up to a modern 200Mhz ARM9. But they all
tend to have to do the same jobs - getting data over a serial line,
process and route the data and transmitting the data over serial lines
where necessary. Needless to say, this environment encouraged people to
keep re-inventing the wheel. And my bosses, engineers from the 70s,
thought this was the ''natural'' way of doing things.

I believed in the portability of C and was appalled at this set-up.
Especially the re-inventing the wheel part. So I started writing
portable code for ''simple'' stuff like CRC16 and base64 encoding etc.
using #ifdefs to select the appropriate implementations for resource
starved systems (PICs on average only have 20 bytes of ram). Then I
moved on to more complex stuff like a Modbus protocol engine.

Then the real struggle began - trying to convince people that this is
the way to go. I''ve already won converts among my team members since
they find it nice to be able to simply browse through my shared folder
of libraries to get what they needed. Slowly people started to
appreciate the effect of fixing a bug in a file fixes it for all
platforms.

The change in attitude towards writing code resulted in a huge library
of re-usable code. This allowed us to concentrate on adding new
features as well as freed us from being dependent on a single
CPU/platform. When our competitors shifted from 68000''s to PPCs we were
able to do the same. When ARM became all the rage in embedded devices
we were able to move our product to it as well.

So, I''ve written code to work all the way from 4MHz, 8bit CPUs with 20
bytes of ram to 200MHz, 32bit CPUs with 128MB of ram and a hard disk.
The complete programs are obviously not portable since you can''t expect
a 1MB program to fit on 1kB of EEPROM. But the code I''ve written, by
themselves, are portable. main() should ideally be the only
non-portable part of your code.


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

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