Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I'm curious if there's a programming language that you can write code for all operating systems in, and if so what language that might be? I'm guessing something very low-level like Binary could do this, but am not sure.

share|improve this question

closed as not a real question by vartec, Bryan Oakley, Jesse C. Slicer, Joel Etherton, Martijn Pieters Mar 8 '13 at 15:09

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

This question is a bit too open ended to be very useful. What do you intend to do with the answer? Are you trying to focus your learning, or are you just trying to gain a better understanding of the world of software development, or something else...? – Bryan Oakley Mar 8 '13 at 14:48
@BryanOakley tried to make the question a bit more specific and correct, hope the edit helped – Jimmy Hoffa Mar 8 '13 at 14:49
When you say "all operating systems" do you really mean all, or are you asking only about Windows, OSX, and Linux? There are many more OS's than just the "big three" -- iOS, Android, other embedded OS's, realtime OS's, etc. – Bryan Oakley Mar 8 '13 at 14:57
Do you really mean "all" OSes? Including extinct species like Multics, exotic stuff like Oberon OS, and experimental ones, like Singularity? – SK-logic Mar 8 '13 at 15:07
That being said, if you want cross-platform-ness, you'll usually want to look at a high-level language, not a low-level one. – Joe Z. Mar 8 '13 at 15:11

4 Answers 4

Operating systems are not concerned with languages. Language implementations (compiler, interpreter, runtime libraries, etc.) are concerned with at least the language, and often with the OS too.

For most pairs of operating systems and languages, there could very well be an implementation that runs programs written in this language on that operating system. There isn't always a mature one readily available, especially for more obscure OS or obscure languages. I say most combinations because the language may demand things the OS does not offer in any form and that are impractical to implement in the language implementation (e.g. a file system). In those cases, you either remove those parts from the language or don't support that OS -- either way, you can't run all programs on that OS.

In practice, less mainstream OS don't support things which aren't absolutely vital, but are used in the existing language implementations, and the value of supporting it doesn't outweigh the problems with supporting it (either by removing the requirement of the existing code, or by writing a new language implementation from scratch). Some examples are hardware threads plus related primitives, support for specific native data types, or memory-related primitives such as allocating memory, setting the protection (read/write/execute) of pages, or the presence of virtual memory.

In practice, some subset of C is supported by almost all operating systems. Whether it makes sense to restrict yourself to the intersection of those subsets is another question entirely (hint: 99% of the time it doesn't). Still, sticking to ANSI C and libraries that do the same (or are ported to a wide range of architectures and OS) is a good first step to making your code run virtually everywhere. It's harder than it sounds though.

share|improve this answer
+1 for the first paragraph. – Caleb Mar 8 '13 at 15:03
I'd like to thank you for your time and knowledge. – Nikola Tesla Mar 8 '13 at 15:06
OS/400 is an operating system that is particularly bad at supporting C. It doesn't have pointers and it doesn't have files. Still, there are C implementations for it, they basically run in an emulation layer. (Nowadays, it's not such a problem anymore, because modern versions of OS/400 contain a POSIX layer.) – Jörg W Mittag Oct 21 at 18:31

There are several layers of complexity and abstraction to be aware of here:

  • the programming language (C, C++, Java, Python, Haskell, ...)
  • the machine architecture (x86, x64, ARM, ...)
  • the operating system services (ABI, e.g. POSIX, Win32)

Multiple compilers for a single programming language can support several machine architectures - which means that the language can compile to the machine code of the target architectures (e.g. C, C++, available for many platforms), or that the language can be translated to an intermediate representation, and there is a run-time environment available that can run this intermediate representation for the target architectures (e.g. Java, .NET/Mono).

Being able to compile to a machine architecture isn't necessarily enough because you can have multiple operating systems for the same architecture, and to be able to do useful work on a particular architecture with a particular operating system your language and its libraries must support the facilities of that operating system (aka the ABI).

This is also why you will often see project configurations for a single programming language specified as "Windows"(OS) "x64" (architecture), "iOS x86", "iOS ARM", etc..., because both those settings can vary independently

share|improve this answer
I'd like to thank you for your time and knowledge. – Nikola Tesla Mar 8 '13 at 15:07

Binaries (executable files) must adhere to two things:

  1. The CPU being used
  2. The ABI being used

There is no such format that works on all CPU:s and OS:s in use.

In practice, no sane person writes a binary by hand. That's what compilers are for. Compilers translate your high-level instructions into the format expected by the OS and CPU. So the correct answer would be:

Whatever language that can compile down to the binary format expected by the CPU and OS. In most cases, this means C.

share|improve this answer
I'd like to thank you for your time and knowledge. – Nikola Tesla Mar 8 '13 at 15:15

All operating systems is a very tall order. There's no language that matches that description. The C programming language is probably the most widely available language, though even it likely isn't available on literally all operating systems.

You could say that all OS's support assembly language, though there are many different, incompatible assembly languages out there.

share|improve this answer
Though, you won't find it on many mobile devices. - You can program android with C using the android NDK. iOS is programed using objective C, which is a runtime on top of C. Between these two, this accounts for many, if not most mobile devices. – MichaelT Mar 8 '13 at 15:08
@MichaelT: while True, if one were to set out to learn C so they could program on iOS, I think they might be disappointed. I don't think you can actually compile and run an ANSI C program on iOS, can you? – Bryan Oakley Mar 8 '13 at 15:21
You can, its just a "bit" more challenging to interface with the system itself to do the calls for the ui and events and what one considers 'core' iOS features. I've got a few hybrid apps where I wrote some libraries in old fashioned C and then called them from an objective C shell. There are a number of SO questions about this. The classic console input/output C app isn't something that one does easily on iOS (in any language). – MichaelT Mar 8 '13 at 15:27
@MichaelT: that's cool, I didn't know you could go old school on iOS and use straight C. Interesting. I'll modify my answer. – Bryan Oakley Mar 8 '13 at 15:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.