Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is C cross platform?

C language is ultimately compiled to machine specific assembly language. Then how can C be cross platform if every processor has its own assembly language syntax? If I write an operating system kernel in C then how can I make it run across a variety of processors?

like image 817
Abhishek Sharma Avatar asked Jan 23 '19 09:01

Abhishek Sharma


People also ask

How is C not platform dependent?

C is not platform dependent because it does not generate the uniform executables. suppose if we have build C code and generated binary in Windows and this same binary will not work on Linux.

How is C platform dependent?

Originally Answered: is c platform dependent? C Compiler is platform dependent since it is closely linked to the OS kernel which is different for different OS. But over the years all OS's come with pre-installed compilers and libraries that make it quite platform independent for basic programming.

Is C sharp cross-platform?

Yes, C# is fully cross-platform thanks to . NET Core. . NET Core is a free and open-source, managed computer software framework for Windows, Linux, and macOS operating systems. It is the cross-platform successor to the .


2 Answers

C is portable at the source code level. This means that you can recompile your program in the platform of choice and have your application running there.

You can find the history of C in the wikipedia, for example. At that time, programming was carried out in assembly for each specific machine, so having a high-level (by that time) programming language was a bless: it sped up development and also made possible to port programs from one machine to a new one just by porting the compiler (the C compiler could later be written in C itself, again speeding up the porting process, but that's another story).

Specifically, the idea of porting UNIX between operating systems appeared when they had UNIX running in the PDP-7, and the PDP-11 appeared. Finally, even UNIX's kernel was rewritten in C, so it made the operating system really popular because of the easy porting: there was only the need to write a small amount of assembly for very specific parts of the kernel, so you could have UNIX up and running in a new machine shortly, at least compared to other operating systems of that time.

like image 139
Baltasarq Avatar answered Oct 12 '22 13:10

Baltasarq


The language C itself is cross-platform, because you don't directly run C code on machines. The C source code is compiled to assembly, and assembly is the platform specific code. The only non cross-platform part are the compilers and the resulting assembly.

In essence, you can use the same C code, with different compilers, to create the specific assembly needed. Since you use the same C source code, its deemed cross-platform.

like image 4
dantechguy Avatar answered Oct 12 '22 13:10

dantechguy