HISTORY OF C
The C language was developed at AT&T Bell Labs in the early 1970s by Dennis Ritchie. It was based on an earlier Bell Labs language "B" which itself was based on the BCPL language. Since early on, C has been used with the Unix operating system, but it is not bound to any particular O/S or hardware.
C has gone through some revisions since its introduction. The American National Standards Institute developed the first standardized specification for the language in 1989, commonly referred to as C89. Before that, the only specification was an informal one from the book "The C Programming Language" by Brian Kernighan and Dennis Ritchie.
The next major revision was published in 1999. This revision introduced some new features, data types and some other changes. This is referred to as the C99 standard.
Before we embark on a brief tour of C's basic syntax and structure we offer a brief history of C and consider the characteristics of the C language.
In the remainder of the Chapter we will look at the basic aspects of C programs such as C program structure, the declaration of variables, data types and operators. We will assume knowledge of a high level language, such as PASCAL.
It is our intention to provide a quick guide through similar C principles to most high level languages. Here the syntax may be slightly different but the concepts exactly the same.
C does have a few surprises:
Many High level languages, like PASCAL, are highly disciplined and structured.
However beware -- C is much more flexible and free-wheeling.
This freedom gives C much more power that experienced users can employ.
The above example below (mystery.c) illustrates how bad things could really get.
The milestones in C's development as a language are listed below:
UNIX developed c. 1969 -- DEC PDP-7 Assembly Language.
BCPL -- a user friendly OS providing powerful development tools developed from BCPL. Assembler tedious long and error prone.
A new language ``B'' a second attempt. c. 1970.
A totally new language ``C'' a successor to ``B''.
By 1973 UNIX OS almost totally written in ``C''.
Characteristics of C
We briefly list some of C's characteristics that define the language and also have lead to its popularity as a programming language.
Naturally we will be studying many of these aspects throughout the course.
Small size
Extensive use of function calls
Loose typing -- unlike PASCAL
Structured language
Low level (BitWise) programming readily available
Pointer implementation - extensive use of pointers for memory, array, structures and functions.
C has now become a widely used professional language for various reasons.
It has high-level constructs.
It can handle low-level activities.
It produces efficient programs.
It can be compiled on a variety of computers.
A C program basically has the following form:
{
Pre-processor Commands
Type definitions
Function prototypes -- declare function types and variables passed to function.
Variables
Functions
We must have a main() function.
A function has the form:
type function_name (parameters)
local variables
C Statements
}
If the type definition is omitted C assumes that function returns an integer type.
So returning to our first C program:
/*Sample program */
#include"stdio.h"
#include"conio.h"
main()
{
printf( ``I Like C $\backslash$n'' );
exit ( 0 );
}
C requires a semicolon at the end of every statement.
printf is a standard C function -- called from main.
$\backslash$n signifies newline. Formatted output -- more later.
exit() is also a standard function that causes the program to terminate. Strictly speaking it is not needed here as it is the last line of main() and the program will terminate anyway.
Getting set up - finding a C compiler
The very first thing you need to do, before starting out in C, is to make sure that you have a compiler.
What is a compiler, you ask? A compiler turns the program that you write into an executable that your computer can actually understand and run.
If you're taking a course, you probably have one provided through your school. If you're starting out on your own. If you're on Linux, you can use gcc. and if you're on Mac OS X, you can use xcode.
If you haven't yet done so, go ahead and get a compiler set up--you'll need it for the rest of the tutorial.
The C Compilation Model
| source code
|
V
prossesor
|
|
|
V
compiler
|
| Assembly code
|
V
Assembler
|
libraries |
|
| object code
V
link editor
|
|
V
The Preprocessor
some basic information for some C programs.
The Preprocessor accepts source code as input and is responsible for
removing comments
interpreting special preprocessor directives denoted by #.
For example
#include -- includes contents of a named file. Files usually called header files. e.g#include
#include
#define -- defines a symbolic name or constant. Macro substitution.
#define MAX_ARRAY_SIZE 100
C Compiler
The C compiler translates source to assembly code. The source code is received from the preprocessor.
Assembler
The assembler creates object code. On a UNIX system you may see files with a .o suffix (.OBJ on MSDOS) to indicate object code files.
Link Editor
If a source file references library functions or functions defined in other source files the link editor combines these functions (with main()) to create an executable file. External Variable references resolved here also.
No comments:
Post a Comment