什么时候代码被认为是平台无关的?
This question arose as the result of a discussion on the reply to a question about platform-independence of PhysicsFS library. The question is whether particular code could be considered cross-platform or platform-independent? Should the code conform to certain standards or maybe just run on a particular set of platforms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个很好的问题!我冒险在这里猜测,所以请耐心等待,因为我确实没有明确的答案。
我认为“平台独立”是指由隐藏基础设施的东西运行的代码。例如,JVM 对语言隐藏了平台——语言中没有任何东西可以让您访问平台——因此具有平台独立性。
我相信跨平台是一种与平台细节无关的东西——例如 JavaScript:你可以访问浏览器及其所有的怪癖。因此,编写在所有浏览器上运行的 Javascript 代码将是跨浏览器的——我认为你可以将其推断为“跨平台”。
That's a very good question! I am venturing to guess here so bear with me as I don't have a definite answer really.
I think "platform independent" refers to code that is run by something that hides away the infrastructure. For instance the JVM hides the platform from the language -- there is nothing in the language that gives you access to the platform -- hence the platform independence.
Cross platform I believe is something that is not shielded away from the details of the platform -- think JavaScript for instance : you have access to the browser and all of its quirks. So writing Javascript code to run on all browsers would be cross-browser -- and you can extrapolate this I think to "cross platform".
平台无关:如果编译器/系统库/VM/等...符合该语言/库/等的标准...,则代码必须在遵守规定标准的每个未来平台上编译/运行。这意味着代码无法在任何地方使用依赖于平台的
#ifdef
,并且程序不会访问上述标准中未定义的 API。跨平台:这是一种模棱两可的情况,而且主要是个人喜好。对我来说,这意味着它至少可以在三大平台/操作系统中的两个上运行(x86(_64) Windows、Linux 和/或 Mac)。在大多数情况下,它可以在更多的平台和体系结构上工作,并使用一些或大部分 POSIX API 功能(至少对于非 Windows 代码)。它将包含有限数量的#ifdef,用于为需要它的平台(posix vs win32 vs...)调用专用 API。
Platform-independent: if the compiler/system library/VM/etc... are standard conformant for that language/library/etc..., the code must compile/run on every future platform that adheres to the prescribed standard. This means that the code cannot use platform-dependent
#ifdef
s anywhere, and that the program does not access API's not defined in said standard.Cross-platform: this is kind of ambiguous, and mostly personal preference. For me, it means that it runs on at least two of the three big platform/OSes (x86(_64) Windows, Linux, and/or Mac). In most cases it will work on a lot more platforms and architectures, and use some or mostly POSIX API functionality (at least for non-Windows code). It will contain a limited number of
#ifdef
s to call specialized API's for platforms that require it (posix vs win32 vs...).