Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!tahoe!bally!siva From: siva@bally.Bally.COM (Siva Chelliah) Newsgroups: comp.lang.c Subject: Re: Unix and C Message-ID: <403@bally.Bally.COM> Date: 9 Nov 90 00:38:43 GMT References: <4458@mint39.UUCP> Reply-To: siva@bally.UUCP (Siva Chelliah) Organization: Bally Mfg. - Reno, Nevada Lines: 62 In article fraser@bilby.cs.uwa.oz.au (Fraser Wilson) writes: >In <4458@mint39.UUCP> gunda@motcid.UUCP (Indira Gunda) writes: > >>richb@railnet.UUCP (Richard Banks) writes: > >>>How can Unix be written in C ? I thought all OS`s had to be written >>>in assembly language, else they'd have the same interrupts as the >>>OS you booted your complier language under to write the program ? > >>Yes ... Why and how can UNIX be written in C? I'd also like to know. > >Why? Because it makes it very portable. Any machine that has a C >compiler and a few kernal routines (actually a fair number) can run Unix >fairly easily. If Unix were written in assembly, it would have to be >completely rewritten for every new computer it runs on. This discussion reminds me of something. Q: How is the first compiler is written ? A: In assembly language. Q: How is the first assembler is written ? A: In machine language. Q: If you have just the hardware, how would you feed the machine language into the computer ? A: I thing you should burn the machine language into a chip, that would accept a machine language from the user, and execute it. > >How? Well, you have a few system calls to assembly routines, and then >write lots of C to use them. The C compiler itself is written in C. > Assume you have a C compiler ( write it any way you want - assembly, or Pascal or anything ). It can be as sloppy as you want. Let's call it sloppy_comp_sloppy.exe sloppy_comm_sloppy.exe ===> a C compiler which is sloppy(doesn't do any optimization) Now write a optimizing C compiler in C call it opti_comp.c opti_comp.c ===> a C compiler that will optimize other C programs. compile this with sloppy_comm_sloppy.exe , and you will get opti_comp_sloppy.exe ==> it is a sloppy exe file (will run slow, but will compile other C programs and produce good exe programs) Now, compile opti_comp.c using opti_comp_sloppy.exe, and you will get opti_comp_opti.exe ===> an optimized exe file which will produce other good exe programs. So we started with a sloppy C compiler and using that we produced a optimizing C compiler ( which itself is optimized). Siva siva@bally.bally.com