Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are programs coded separately for different operating systems?

Tags:

c++

windows

macos

If a program was written in c++ to run on Windows, does it have to be completely rewritten to run on Mac OS or a mobile OS?

like image 468
avon_verma Avatar asked Jan 05 '11 03:01

avon_verma


People also ask

What programming language works on all operating systems?

C is the programming language most commonly used and recommended for writing operating systems. For this reason, we are going to recommend learning and using C for OS development. However, other languages such as C++ and Python can also be used.

How are operating systems coded?

Most of the operating systems are written in the C/C++ languages. These not only include Windows or Linux (the Linux kernel is almost entirely written in C), but also Google Chrome OS, RIM Blackberry OS 4.

Is it possible to run a software on a different operating system?

It's possible to run multiple OSes on a single machine either by dual booting or using a virtual machine. For most people, there's no such thing as a "best" OS. You're fine using the OS you're most comfortable with.

Is operating system and program the same?

An operating system (OS) is the program that, after being initially loaded into the computer by a boot program, manages all of the other application programs in a computer. The application programs make use of the operating system by making requests for services through a defined application program interface (API).


3 Answers

C++ is a standard language, which means that the source code that you write can be compiled on any platform which has an implementation of the C++ standard. There are two ways you can write C++ programs that can't be compiled on different implementation. First, if you use language extensions that are found on a specific (set of)implementation(s) only. Second, using a library that depends on code that doesn't ship with the standard library(like on OS API).

For the first matter, try always to write standard code. For the second, use cross-platform libraries like Boost, Qt...

like image 94
Khaled Alshaya Avatar answered Sep 25 '22 16:09

Khaled Alshaya


Typically, yes, because the program will need to use OS-specific features for windowing and possibly for other features as well (networking, synchronization, etc.) However, many programs try to mitigate this as much as possible by building wrapper classes so that most of the program deals with these wrappers rather than the raw platform-specific tools. To port the program from one platform to another, you just need to reimplement the wrappers using the new platform's tools.

Many programs take this a step further by using prewritten libraries like Qt or Boost to handle some of the cross-platform silliness, but this is (essentially) the above idea at a larger scale.

like image 32
templatetypedef Avatar answered Sep 25 '22 16:09

templatetypedef


This depends. In general, Standard C++ is a general-purpose, portable language which can be compiled to run on any system or platform that has a standard-compliant compiler.

However, a lot of the more "interesting" features you might want to add to a typical application are not part of Standard C++. This includes GUIs, threads, sockets, and low-level OS API calls. These are generally not portable, and parts of the code which use these features will need to be implemented separately for each operating system or platform.

Fortunately, this is not as daunting as it sounds, because there are a lot of cross-platform libraries in existence that have already gone through the trouble of doing this. For example, the Boost threading library already has threading code written for different platforms or operating systems, but all of this is abstracted behind a nice uniform API that can be used portably in C++ application code.

Additionally, a lot of non-Standard C++ code still conforms to some standard, such as POSIX, which is supported across multiple platforms. For example, most UNIX-ish systems, including Linux and Mac OS X, support POSIX threads (the pthread API).

like image 32
Charles Salvia Avatar answered Sep 24 '22 16:09

Charles Salvia