Sunday, August 29, 2010

C and UNIX

As we have seen, C is intimately related to the UNIX operating system, whic is written almost entirely in C. UNIX is composed of a kernel, one or more shells, and a large set of service routines. The kernel is small, about 10,000 lines of code, which creaters a virtuals machine that:

  1. Schedules, coordinates, and manages procces execution
  2. Provides system services such as I/O
  3. Handles machine-dependent hardware operations [Silvestre, 1983]
All but the set of machine primitives tailored to the particular computer on which  UNIX is running are written in C. The user rarely sees the kernel, but interacts with the set of procedures comprising one of the shells.

A UNIX system provides a variety of utilities such as editors, debuggers, and preprocessors as well as compilers for BASIC, FORTRAN, RATFOR, PASCAL (at least in the Barkeley version),C, and Assembler. Source code in any of these languages is first translated into C intermediate code before being translated into Assembler, relocatable object, and finally executable machine-language code.
Since all programs are first translated into C, new compilers are particulary easy to write. All one need do is design a translator into C, with no writing of Assembler code. This translator also enables the mixing of code written in different source languages and interfacing with applications such as databases, spreadsheets, and graphics programs.

To understand and can understand about it all, we must first know the standard of the language C. Whether the standard of the C language? Let's discuss together.


The C standard  
The de facto standard for C has been Kerninghen and Ritchie's book [Kernighan,1987]. There is now, however, a standard from Technical Commite X3J11 of the American National Standards Institute [ANSI/ISO-9899, 1990]. All C compilers will now be excepted to conform. When adopted by the International Standads Organization (ISO), it was basically identical to the ANSI standard. Since there was some weakness in the provision for locale-dependent features (e.g.,comma or period for decimal point, month/day/year versus day/month/year, or a different alphabetic sequence), the ISO adopted an Amendement 1 in 1994 [ANSI/ISO-9899,1994], which is now part of the standard.
Commite X3J11 was guided by several principles, the most important being, "Don't make presently working code obsolete." That is, programs written in correc kernighan/Ritchie code should still compile and run.
Others advocate both portability and system-dependent C. The commitee tried to preserve C pretty much as it exists, and not "fix" it.
The main disadvantage of C is the difficulty of debugging programs due to automatic type coercions, pointer arithmetic, and side effects within expressions. It also fosters a terse programming atyle that is somtimes hard for anyone but the program designer to read. Thus it is often not the preferred language for business or scientific applications. Its closeness to the machine, however, makes it ideal for writting operating systems and compilers. It is also very flexible for interactive programming, due to the variety of I/O facilities.

No comments:

Post a Comment