OPERATING SYSTEMS

VMS VAX systems
Unix Open system; variates include Gnu, Linux, Sun/Solaris
MS-DOS Intel/Microsoft
Macintosh PPC (IBM and Motorola)/Apple
Windows95 Intel/Microsoft
Windows/NT Intel/Microsoft
Rhapsody Intel and PPC/Apple & NeXT

A Brief History of Programming Languages

Time Events Procedural Structured Object-Oriented
1950 early mainframe assembly
1955   FORTRAN, COBOL  
1960     ALGOL
1965 network computing BASIC LISP (sort of)
1970   PL/1 Pascal
1975 minicomputer; Unix   C
1980 personal computer   Ada
1985 Macintosh GUI     Object Pascal; C++
1990   Visual Basic
1995 WWW   perl Java

Why we are learning C

1. ANSI C will run on virtually any machine with no modifications

2. The syntax is similar to that used in C++ and Java

3. It is a structured language with the standard set of control structures

4. Until recently, C was the most common language for applications development

5. It produces very fast code


Problems with C as an initial language

1. It has a very rich set of functions and operators, most of which you can safely ignore;

2. Many of these functions are very idiosyncratic;

3. It does not provide array bounds checking; instead it crashes the operating system;

4. There are usually multiple ways to do anything in C, and the most efficient code is frequently the most obscure.


Process of creating a C program

Tool Tasks
Paper 1. Define the program objectives
2. Figure out the appropriate algorithms
Text editor Write the program
Compiler 1. Check the syntax
2. Convert the program to assembly language
Linker Add the appropriate libraries
Run Run the program in the operating system

IDE: Integrated development environment

These combine an editor, compiler/ linker and a debugger into a single system. Files are usually organized into "projects" that keep relevant information together.


Buzz words

ANSI American National Standards Institute
ASCII American Standard Code for Information Interchange
byte 8 bits of memory (=one character)
Mb megabyteÑroughly 1-million bytes
RAM random access memory

Writing Bug-free Code

  1. Test every procedure as you write it or modify it -- don't assume that it is working.
  2. Document, document, document -- don't assume you will remember your logic in six months.
  3. Assume that any input will contain errors and anticipate them.
  4. Keep your functions small -- ideally they should fit on a single page (i.e. screen);
  5. Be sure that you fully understand the ANSI functions you are using, particularly how they operate when errors occur.
  6. Don't be too clever; if you must be, thoroughly document your cleverness.
    A modern optimizing compiler will in all likelihood create a more efficient implementation if you just use a straightforward algorithm.
  7. Be systematic in your use of variable names.
    Avoid 1/l (one/el) and O/0 (oh/zero) in names.
  8. Find the source of errors, don't just write conditional statements to get around them. A replicable bug is your friend.

Structure of a C program

// initial documentation
#include include library headers
(preprocessor)
#define define global constants
(preprocessor)
int n
char aline[14]
allocate global memory
void main(void) main function
int funct1(int n)
float funct2(int n)
void funct3(void)
remaining functions

Conditional Statement

if () ; if () ; else ; If the evaluates to a nonzero value, is executed. Otherwise it is skipped; in the second form is executed.

Comparison Operators

== equal [Warning: this is the single greatest source of C bugs!!]

!= Not equal

<, > less than, greater than

<=,>= less than or equal, greater than or equal

Logical Operators

! not

&& and

|| or


Formatted Output

printf(format string, variable list);

fprintf(file ptr, format string, variable list);

Common formats

%d output an integer
%f output a floating point number
%c output a character
%s output a string

Adjusting length

%8d output right-justified 8-digit integer
%5.2f output 2 digits to right of decimal; 5 characters total (including the .)
%10s output a string of at least 10 chars
%5.5s output a string of exactly 10 chars

Special characters

\t tab
\n new line
\" double-quote
\' single-quote
%% % "percent sign"
\\ \"backslash"

Incrementing an integer

int n

n = n + 1; (similar to BASIC, Pascal)

n += 1;

n++; (get value, then increment)

++n; (increment, then get value)