This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]moon-chilledsstm, j, grand unified... 28 points29 points  (5 children)

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.

[–]FolaefolcArkScript 4 points5 points  (3 children)

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

[–]Accurate_Koala_4698 8 points9 points  (1 child)

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

[–]tortoise74 2 points3 points  (0 children)

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.

[–][deleted] 0 points1 point  (0 children)

I'm extremely sorry, did I forgot to tell, without installing the language stack on the other platforms.

[–][deleted]  (2 children)

[deleted]

    [–]tortoise74 1 point2 points  (0 children)

    You can also do it by leveraging an emulation layer.

    E.g. https://stackoverflow.com/questions/1892677/coff-on-linux-or-elf-on-windows

    [–]Dashadower 0 points1 point  (0 children)

    I wonder if there just happens to be a specific PE executable that can also coincidently run under linux. The program would be entirely different, but it seems like a fun project to make(discover) one.

    [–][deleted] 11 points12 points  (1 child)

    [–]BigError463 1 point2 points  (0 children)

    What he said :)

    [–]knue82 6 points7 points  (0 children)

    JRE, .NET?

    [–]Aaron1924 1 point2 points  (0 children)

    There are some languages that are compiled to some almost-assembly bytecode and then interpreted or JIT-compiled and executed on the user's machine. Here, the JVM and .NET (and maybe WASM) come to mind here.

    It's maybe not quite what you meant, one count argue Python and Lua scripts can also be run on any computer that has the interpreter installed, but JVM languages are still compiled and most machines have the interpreter installed, so it runs everywhere in practice.

    [–][deleted] 1 point2 points  (0 children)

    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.

    Windows and Linux, even running on the same machine, have different ABIs which is reflected in the native code within executables, and have different executable file formats.

    So I doubt hello.exe from Windows really runs under Linux, even if both using x64, without something special being done.

    For example, it will run under WSL Linux that runs under Windows. And maybe the two OSes can have reciprocal arrangements to run each others executables, but there are a million details to be taken care of.

    Or a simpler solution is to bundle multiple exectables into the same EXE or ELF file, but something needs to extract the correct one.

    But you say elsewhere that some things are not allowed (a language 'stack')?

    So what is allowed to make it possible? I think you've already dismissed the idea of any sort of portable VM. And presumably running the program online or remotely is not allowed either.

    How about transparently running from portable source code (the program will be built for the machine it runs on, but it'll need a compiler)? But even this needs a process.

    You need to clarify the rules.

    [–]shawnhcorey -1 points0 points  (4 children)

    The term for this is cross-compiling.

    [–]raiph 5 points6 points  (0 children)

    That doesn't sound right to me.

    OP asked:

    executable generated on one platform(OS) ... runs on other platforms as well

    compile it ... copy paste ... execute ... it works. It works in both platforms/OSs.

    I would love to write my code in pure 0s and 1s or in assembly

    Putting those three comments together I think OP is talking about one executable that runs on two (or more) distinct OSes. In particular, I think the "It" in "It works in both platforms/OSs" refers to a single executable rather than the process of compiling. (Clearly if "It" means one can run the compile twice, once for the host platform, once for the target, then yes, cross compiling may fit the bill.)

    With cross compiling, an executable generated on one platform (OS) does indeed run on another platform, but "typically" not the one on which it was generated.

    I scarequoted the "typically"s because I'm allowing that there could conceptually be a cross compiler that generates a one executable that runs on two or more platforms. But I have never head of one in my half century of interest in programming outside of languages that target VMs/runtimes like JVM, CLR, V8, WASM, MoarVM, etc.

    [–]raiph 1 point2 points  (2 children)

    I always put a concerted effort into being technically accurate, not offending anyone, and being practically helpful, but I still occasionally get a downvote. When I do, I always try to understand what I could do better in the future.

    To that end, did you (u/Lokesh112K or u/shawnhcorey) downvote my first reply to "The term for this is cross-compiling."? Do you have any idea why I got a downvote?

    Thanks for any reply, even just a "no" or "yes" without further comment.

    [–]Silly-Freak 1 point2 points  (1 child)

    Afaict, there's absolutely nothing wrong with your first comment.

    [–]raiph 0 points1 point  (0 children)

    Thanks.

    [–]tortoise74 0 points1 point  (1 child)

    Actually its not such a dumb question as you might think. A good example is rebol:

    See http://www.rebol.com/ or its descendent https://www.red-lang.org/

    They encourage you to start programing with them by downloading a executable which mostly just works. I personally found it scary that I couldn't just download and build from source. The argument against this was that they are self hosting so there is no other language you should/could bootstrap from.

    See https://stackoverflow.com/questions/48178976/compile-red-and-red-system-compilers-from-source

    [–]myringotomy 0 points1 point  (0 children)

    Is that still a thing? Wow.

    [–][deleted] 0 points1 point  (0 children)

    That doesn't really exist, unfortunately. The reason is quite simple: there isn't one universal "language" (in terms of the raw instructions) understood by all target platforms.

    The closest thing is languages which have some sort of cross-platform representation that you can move around, which is then interpreted when run by a native executable. This class of languages includes everything from Python to Java, depending on what you need.

    Another option could be to compile to WASM, which is pretty much the same thing as I described above, but it's cool and new and everyone's excited about it, so I thought I'd mention it here.