为什么很难编写可移植的C程序? [英] Why is it difficult to write portable C programs?

查看:141
本文介绍了为什么很难编写可移植的C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,为什么太硬,使许多操作系统,如Windows和Linux上运行的程序,而不包括胶水code。他们都共享相同的体系结构(x86),所以我觉得应该是很简单。此外,C是标准化的,所以为什么实现这些操作系统diferent?为什么难以遵循标准,并推行全民库的所有操作系统?

I want to know, why is it too hard to make a program run in many OSes, like Windows and Linux, without including glue code. They all share the same architecture (x86), so I think it should be simple. Furthermore, C is standardized, so why are implementations diferent in these OSes? Why is it hard to follow the standard and implement a universal library for all OSes?

我用C编程了将近两年,目前我用巧舌如簧的可移植性。

I have programmed in C for almost two years, and currently I use glib for portability.

我不是在寻找一个解决这个问题,我已经使用油嘴滑舌用于这一目的。但我想知道为什么是必要的,它为什么难治使C库没有差别。

I'm not looking for a solution to this problem, I'm already using glib for this purpose. But I want to know why it is necessary, why it's dificult to make a C library without differences.

[ADD]

例如,当我写在C /油嘴一个程序,我用的是gchar / gint等类型确实的C基本类型,在大约巧舌如簧维基百科,它说:

For example, when i write a program in C/Glib, i use the gchar/gint and so on types indeed the C primitive types, in wikipedia about glib, it says that :

功能

在初级水平提供GLib的类型定义替换C基本类型字符,整型,浮点,等等,以提高便携性

On an elementary level GLib provides type definitions replacing the C primitive types char, int, float, and so on in order to improve portability"

为什么ç基本类型是不可移植,整个语言?

Why C primitive types is not portable and the whole language?

感谢所有的答案。

推荐答案

制作了一个计算的一点,打印结果的工作你的基本的C程序很容易。

Making your basic C program that computes a little and prints results work is easy.

问题在于,做任何实质性任何C程序将依赖于从操作系统很多服务,并在许多方面有所不同。文件I / O往往是相似的,但是当涉及到​​图形,它们之间的区别很多。这就是问题的症结所在。

The problem is that any C program that does anything substantial is going to rely on a lot of services from the operating system, and those differ in many ways. File I/O tends to be similar, but when it comes to graphics, they differ a lot. And that is the crux of the problem.

这篇关于为什么很难编写可移植的C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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