Lecture notes Wednesday 1/13/99
What is programming?
- to command computers
- to write software
- to give instructions how to perform actions/ computations and make decisions
computer program = set of instructions that control how computers process data
computer languages
3 types:
- machine language:
- strings & numbers, directly understandable by computer, cumbersome for humans, machine-dependent
- assembly language:
- English-like abbreviations, need translation: assemblers, require many instructions for simple tasks
- high-level language:
- like "everyday" English & mathematical notations, need translation: compilers
examples: C, Fortran, Cobol, Pascal, Ada, Modula-2; Prolog; Lisp, Scheme, ML; Smalltalk, C++, ...
pros and cons of C
- powerful (easy access to OS services = system calls, libraries)
- widely-used (popular in industry, software development, OS, networking, client/server)
- standardized (ANSI C, hardware independent, portable)
- good starting point/ foundation for C++, Java, Perl, shell scripts, CGI scripts, Tcl/Tk, ... [combined C/C++ product]
power -> possible to write "bad", convoluted code (difficult to read, more likely to behave strangely, more difficult to test & debug)
-> aim for clarity, KIS, structured programming, top-down stepwise refinement, functionalization, oo, ...
the C programming system
- the C language
- the C Standard Library: rich collection of existing functions -> reusability
- the C development environment
typical UNIX-bases C environment: edit, compile, execute
C development environment
- 1. edit:
- type, make corrections, name: .c extension; e.g. vi, emacs, pico
- 2. compile: [gcc welcome.c -> a.out]
- preprocessor: before translation, including other files or replacing special symbols with program text, preprocessor directives
- compiler: translate into machine language code ("object code")
- linker: link object code with code of functions referenced (e.g. libraries) -> "executable image"
- 3. load (place in memory) and execute
take input from stdin (standard input device)
output data to stdout (standard output device)
display error messages to stderr (standard error device)