开发者

When is code considered platform-independent?

开发者 https://www.devze.com 2023-02-27 03:32 出处:网络
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-platfor

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 platfo开发者_StackOverflow社区rms?


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".


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 #ifdefs 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 #ifdefs to call specialized API's for platforms that require it (posix vs win32 vs...).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号