程序如何独立于OS? [英] How a program become independent of OS?

查看:102
本文介绍了程序如何独立于OS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们说一个程序独立于OS时,这到底是什么意思?我们的意思是只要处理器相同,它就可以在任何操作系统上运行?

What exactly do we mean when we say that a program is OS-independent? do we mean that it can run on any OS as long as the processor is same?

例如,OpenGL是一个与OS无关的库.它包含的功能必须假定使用特定的处理器.但是代码/程序/应用程序不是特定于操作系统的吗?

For example, OpenGL is a library which is OS independent. Functions it contain must be assuming a specific processor. But ain't codes/programs/applications OS-specific?

我了解到的是:

  1. 操作系统是特定于处理器的.

  1. OS is processor-specific.

应用程序(程序/代码/例程/功能/库)特定于操作系统.

Applications (programs/codes/routines/functions/libraries) are OS specific.

源代码是纯文本.

编译器(程序)是特定于OS的,但它可以编译a
的源代码. 假定相同操作系统的不同处理器.

Compiler (a program) is OS specific, but it can compile source code for a
different processor assuming the same OS.

OpenGL是一个库.

OpenGL is a library.

因此,OpenGL必须是特定于OS/处理器的.怎么能与操作系统无关?

Therefore, OpenGL has to be OS/processor-specific. How can it be OS-independent?

可以独立于操作系统的是源代码.这是正确的吗?

What can be OS independent is the source code. Is this correct?

了解源代码是否独立于操作系统又有什么帮助?

How does it help to know if a source code is OS-independent or not?

推荐答案

当我们说一个程序独立于OS时,这到底是什么意思?我们的意思是只要处理器相同,它就可以在任何操作系统上运行?

What exactly do we mean when we say that a program is OS-independent? do we mean that it can run on any OS as long as the processor is same?

当程序仅使用已定义的行为(没有未定义,未指定或实现定义的行为)时,该程序将被保证语言标准(在您的情况下为C语言标准)进行编译(使用符合标准的编译器)并在所有操作系统上统一运行.

When a program uses only defined behaviour (no undefined, unspecified or implementation defined behaviours), then the program is guarenteed by the lanugage standard (in your case C language standard) to compile (using a standards compliant compiler) and run uniformly on all operating systems.

基本上,您必须了解诸如C之类的语言标准或诸如OpenGL之类的库标准会提供一组程序员可以构建和构建的最低假定保证人.只要编译器符合标准(对于库,实现是符合标准的),并且程序不会进入未定义的行为领域,这些都不会更改.

Basically you've to understand that a language standard like C or a library standard like OpenGL gives a set of minimum assumable guarentees that a programmer can make and build upon. These won't change as long as the compiler is compliant with the standard (in case of a library, the implementation is standards-compilant) and the program is not treading in undefined behaviour land.

openGL必须是特定于OS/处理器的.怎么能与操作系统无关?

openGL has to be OS/processor specific. How can it be OS-independent?

不. OpenGL与平台无关. OpenGL 实现(实现调用的驱动程序)肯定是特定于平台和GPU的.说C标准是由GCC,MSVC ++等实现的,它们都是可以编译C代码的不同编译器实现.

No. OpenGL is platform-independant. An OpenGL implementation (driver which implements the calls) is definitely platform and GPU-specific. Say C standard is implemented by GCC, MSVC++, etc. which are all different compiler implementations which can compile C code.

可以独立于操作系统的是源代码.这是正确的吗?

what can be OS independent is the source code. Is this correct?

源代码(如果考虑到可移植性而编写)只是众多此类独立于平台的实体之一.库(OpenGL等),框架(.NET等)等也可以与平台无关.因此,甚至硬件也可以由某个人指定并由其他人实施:ARM处理器是ARM​​制定并由Qualcomm,TI等OEM实施的标准/规范.

Source code (if written for with portability in mind) is just one amongst many such platform-independant entities. Libraries (OpenGL, etc.), frameworks (.NET, etc.), etc. can be platform-independant too. For that matter even hardware can be spec'd by some one and implemented by someone else: ARM processors are standards/specifications charted out by ARM and implemented by OEMs like Qualcomm, TI, etc.

我们的意思是只要处理器相同,它就可以在任何操作系统上运行吗?

do we mean that it can run on any OS as long as the processor is same?

只要您仅使用 cross -platform 组件来构建程序.假设您使用C,一种可移植的语言; SDL ,用于创建窗口,处理事件,帧缓冲区等的跨平台库; OpenGL,一个跨平台的图形库. 现在您的程序将在多个平台上运行,即使如此,它也取决于最弱的链接.如果SDL不能在某些仅J2ME的电话上运行,那么它将没有该平台的库分发,因此您的应用程序将无法在该平台上运行.所以从某种意义上说,没有什么是完全独立的.因此,明智的做法是使用可用于不同体系结构,平台,编译器等的各种库,然后根据目标平台选择所需的库.

Both processor and the platform (OS) doesn't matter as long as you use only cross-platform components for building your program. Say you use C, a portable language; SDL, a cross-platform library for creating windows, handling events, framebuffers, etc.; OpenGL, a cross-platform graphics library. Now your program will run on multiple platforms, even then it depends on the weakest link. If SDL doesn't run on some J2ME-only phone then it'll not have a library distribution for that platform and thus you application won't run on that platform; so in a sense nothing is all independant. So it's wise to play around with the various libraries available for different architectures, platforms, compilers, etc. and then pick the required ones based on the platforms you're targetting.

这篇关于程序如何独立于OS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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