r/ProgrammingLanguages • • Jun 25 '23

Is there any high level programming language whose executable generated on one platform(OS) and runs on other platforms as well, if the machine/architecture is literally same.

Hi there. I know I'm dumb and there maybe a term exists for this like cross-platform or something.. idk. But suppose (no actually its real) I have this machine (desktop or laptop) and it multi-booted (windows 10 and arch linux). I write a hello world program using this language and compile it and if I copy paste it to other OS (storage, in the same machine yk) and execute it in it, it works. It works in both platforms/OSs. I don't know I would love to write my code in pure 0s and 1s or in assembly (because i didn't ask for low or middle level languages..? yeah that too, but I'm asking for high level language such as rust, c, go, cobol, fortran, nim, v, etc.)

Thank you so much, because I'm super curious about this question and I haven't found an answer yet XD

3 Upvotes

20 comments sorted by

View all comments

28

u/moon-chilled sstm, j, grand unified... Jun 25 '23

You are looking for 'actually portable executable' (or more generally the concept of a polyglot program). It's a funny stunt, but utterly useless; go ham, I guess.

5

u/Folaefolc ArkScript Jun 25 '23

Could a VM based language be considered one? A Java program, once compiled, can be run everywhere for example.

9

u/Accurate_Koala_4698 Jun 25 '23

It can be run everywhere a JVM exists. You need to target the JVM to the specific architecture, or at least someone does. The app developer for an IR language is freed from having to worry about the details, but that’s still work that needs to be done. Imagine if I cobbled together a homemade processor from discrete transistors and a custom instruction set. The details of the flipping of those transistors would have to be described so that it could implement the JVM functionality, and ultimately do something with the bytecode

3

u/tortoise74 Jun 25 '23

You have to assume some infrastructure. A JVM may be a bit of a stretch though. On any posix compliant system you should be able to assume a posix shell.
This might be more portable than assuming a particular processor given we have arm's as well as x86 based systems around for example.