Question:
Why Linux is not programmed in 100% C language ?
2013-06-07 21:24:00 UTC
i readed that Unix (original) and freeBSD are programmed in 100% C language

but linux is programmed in both C and Assembly languages

Why

Why linux developers do not made the linux portable ???
Seven answers:
Ratchetr
2013-06-07 21:47:42 UTC
I'm not sure where you read that, but they are wrong, or you read it wrong.



Have a look at the link below, which contains these quotes:



First developed in assembly language, by 1973 it had been ***almost*** entirely recoded in C, greatly facilitating its further development and porting to other hardware.



In 1972, Unix was rewritten in the C programming language, contrary to the general notion at the time "that something as complex as an operating system, which must deal with time-critical events, had to be written exclusively in assembly language".[12] The migration from assembly language to the higher-level language C, resulted in much more portable software, requiring only a ***relatively small amount of machine-dependent code*** to be replaced when porting Unix to other computing platforms.



I added *** around the key bits: ***almost*** and ***relatively small amount...***



That means not 100%. Close, but not 100%.



The reason it isn't 100% is simple: There are certain things that an OS needs to do that simply can't be done using standard C.



For example, think of a desktop PC with an x86 processor. When you first turn on the power, the CPU starts executing in real mode. *nix needs the protected mode capabilities of the x86 (where x > 1) to run.

But there is no standard C library function like switch_to_protected_mode(). To do that, you need to twiddle some bits in the CPU registers. And C doesn't even have a twiddle_register_bits() function.



So...certain bits of code simply have to be written in assembly language. There is no way around it.



What *nix did well was to minimize the amount of assembly required. The vast majority of the OS ***IS*** written in portable C code. So moving the OS to a brand new hardware platform is ***relatively*** easy. But some assembly is required.
adaviel
2013-06-08 04:54:35 UTC
Linux is portable, or has been ported to a lot of different hardware. There are a lot of conditional compilation flags to handle optimization on different hardware. Having truly portable binary code that would run on anything from an 80386 to a 64-bit Opteron would make it slow on more powerful hardware that has extra instructions that don't exist on the older CPUs.



One place that assembly is used is interrupt calls and semaphore handling. If you want to define exactly what instructions are used, and want to know which registers can be safely used in an interrupt routine, you use assembly.



There's another comment "the Linux kernel cannot link with the standard C libraries (since, at their core the C libraries depend on systems calls which are provided by the kernel --- so that would present a classic chicken-and-egg problem)"
SteveO
2013-06-10 00:37:08 UTC
Nothing can beat the level of control you have with assembly, nor the speed of execution; the fact is that if you want complete low level access to your hardware, then you're going to be dabbling with assembly. Compare the use of MINX to Linux in the real world: MINIX may be 100% C, but Linux still beats it despite having assembly code in it. There is actually something I saw once that allowed you to write general assembly that was able to be "converted" to processor specific assembly code. And assembly isn't that difficult to port once you have it already written...just a few tweaks based on the processor due to design differences, but everything is largely the same.
Calvin K
2013-06-09 00:53:31 UTC
If you want to talk about portability, Linux is most portable OS in the world; from small watch to super computer. Programming languages are just tools. Don't get too attached and religious on some tools. Different tools are good at different things and you need to know how or when to use those tools for the best result. Linux is very good at this kind of practicality.



If you want to take portability to religious level, try Java. Their motto is write once, run everywhere. Or was it write once, debug everywhere?



And I don't think Plan 9 is any superior than Linux either. They may claim it's technologically advanced. But does it really matter? I heard about Plan 9 over 10 years ago, but I never saw them. Some nuclear physics labs may have some of them installed, but not in my home. Unless Plan 9 is available for general public for general usage, it's just one of your wet dreams. I know what I'm talking about, because I used have one.
jplatt39
2013-06-08 11:27:17 UTC
Have you looked at the source code? (Also, as Linux just asked on Google+ if you aren't running a 3.10-rc why not?). There are hooks for a wide variety of processors including ARM, x86, PowerPC and Cell. Don't tell me that Linux isn't portable.



Actually what Linux is is a kernel to run a modular operating system with modules from different vendors. It was written to run them on the 386SX and with that background the current structure makes perfect sense. Linux has always been a pragmatic compromise. In fact among the early documentation is some nice work with Andy Tannenbaum which ended with Linus and him exchanging insults.
2013-06-08 23:19:21 UTC
Linux was basically all written in C programming Language, then along came other programming languages and In Linux you have several different kinds of C programming you can install, so I really have no idea why some one would claim or think it is not 100% C programming Language.



If the C programming isn't so called portable it could never be used on every computer there is.
Cupcake
2013-06-08 04:26:45 UTC
Because there are things that Assembly can do better and more efficient at low level than C.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...