Document

advertisement
INTRODUCTION
Instructor : Behnam Hajian
bhajian@scs.carleton.ca
Introduction to Systems Programming - COMP 1002, 1402
Objectives and syllabus
The objectives in this course is:
 To expose students to lower level systems interface only
clearly visible via C.
 To further develop the ability to design programs with
emphasis on the abstract view of data structures.
 To get experience with the low-level implementation of
data structures in C.

To experience programming in the
Large
Objectives and syllabus (continue)
In this course you will learn:
 The structure of a C program
 How to use C/C++ compilers such as MinGW, Cygwin,
GCC,…
 How to execute a C program by platforms such as
Borland C builder, Netbeans IDE, GCC,…
 Variables and memory allocation
 Type conversion, operators
 control statements in C (if-then-else, while, for)
 Function and Procedure, Call by Ref. and Call by Value,
Input, Output
Objectives and syllabus (continue)






Header files, System and Library Calls
Structs and complex data structure
Arrays and String (1-D, 2-D , n-D array)
Pointers and more on dynamic memory allocation, and
de-allocation
Heap, Stack
Linked lists Manipulation
Evaluation and…
5 programming assignments : 50%
 Final Exam: 50%
Website:
 Course material will be available on WebCT: look for the
WebCT link from Carleton’s web site.
Lectures:
 Tuesday & Thursday 6PM - 9 PM @ 502 Southam Hall
Office hours:
 The hour before lecture. @ HP 5270 or HP 5336

TA

Jimin Park
Email: jiminparky@gmail.com
 Mon & Fri 2-4 PM

TextBook
References:
 PPT slides are the most important resource for
final exam. However, reading the textbook is
highly recommended.
TextBook:
 C How to Program, 5th Edition, Harvey M.
Deitel and Paul J. Deitel, both from Deitel &
Associates, Inc.
Computers

What is a computer?
A computational device
 Logical decisions billions of times faster than humans
 Hardware



keyboard, screen, disks, memory, CPU
Software

email, word processing, spreadsheets, OS
Computer Organization



Input unit
 keyboard, microphone
Output unit
 screen, printer
Memory unit
 Random Access Memory (RAM)
 short-term,
 Read
rapid access, low capacity warehouse
only memory ROM
 Smaller
amount of memory
 stable when power off.
 Stores enough code to boot system
Computer Organization


Secondary storage unit
 disks, tapes
 long-term, slow access, high capacity warehouse
Central Processing Unit (CPU): Microprocessor (Intel Pentium,
Motorola power PC): fetches machine instructions from
memory, executes them

Arithmetic and logic unit (ALU)
 calculations, comparisons
 CU
(Control Unit)
 coordinator,
administrator,
Computer Architecture
CPU
Program
Control Unit
ALU
Memory
I/O
Computer Architecture (cont.)
Computing Modes

Batch Processing



one job at a time
Multiprogramming




many jobs simultaneously
multiple jobs, multiple users

standalone units
Distributed computing

Timesharing

Personal computer (PC)
workload distributed over
networks
Client/Server


client machine provides user
interface
server machine provide
computational power and
storage location
Programming Languages

Machine Language
machine/hardware dependent
 Too hard to program in


Assembly Language


English-like operations (e.g., load, store, add)
High-level languages
single statement can accomplish substantial tasks
 English-like statements with mathematical notations

Why C?
Because we have to!
C supports:
 Many situations where it is only language or system
available

 Small,

embedded systems, instrumentation, etc.
Many “low-level” situations that don’t have support for
“high-level” languages
 Operating
systems, real-time systems, drivers
Why not C?

C is very low-level






Data structures must be programmed “by hand” e.g. set,collection,…
Operations must be done out in “long hand”
No support for “object oriented” design
Marginal support for higher-level thought processes
Much, much harder to use than higher level languages/systems
Better alternatives available for almost all applications






Java, Python, Ruby, etc. – many CS situations
Matlab, SimuLink – physical modeling
LabView – instrumentation and control
Excel – accounting and statistics
SQL – billing and transactions
…
What about C++?

Object-oriented thinking






Data abstractions, classes, objects, interfaces
Operator overloading
Inheritance
Lots of other good stuff
…
Backward compatible with C






To some extent
Allows programmer to get close to hardware when needed
Allows programmer to get close to data representation when needed
Not platform independent (like Java)
Still need to be conscious of memory management
…
C Program Development Environment
Standard Steps
1.
2.
3.
4.
5.
6.
Edit
Preprocess
Compile
Link
Load
Execute
A Short History
19

In the beginning …
 Machine
language
 Assembly language


Really primitive!
Too difficult for big projects
One line per machine instruction
So “high level” languages were invented
 Non-recursive:–
Fortran, Cobol
 Recursive:– Algol, Lisp, Snobol, PL/1, etc.
Too advanced!
Too much infrastructure for operating
systems, control systems, many
kinds of projects
C: History
20

Developed in the 1970s – in conjunction with
development of UNIX operating system
 When
writing an OS kernel, efficiency is crucial
This requires low-level access to the underlying
hardware:
 e.g.
programmer can leverage knowledge of how data is
laid out in memory, to enable faster data access
 UNIX
originally written in low-level assembly language
– but there were problems:
 No
structured programming (e.g. encapsulating routines as
“functions”, “methods”, etc.) – code hard to maintain
 Code worked only for particular hardware – not portable
C: Characteristics
21

C takes a middle path between low-level assembly
language…
 Direct
access to memory layout through pointer
manipulation


C is Concise syntax, small set of keywords
Is also a high-level programming language like
Java:
 Block
structure
 Some encapsulation of code, via functions
 Type checking (pretty weak)
C: Dangers
22

C is not object oriented!
Can’t “hide” data as “private” or “protected” fields
 You can follow standards to write C code that looks objectoriented, but you have to be disciplined – will the other
people working on your code also be disciplined?


C has portability issues


Low-level “tricks” may make your C code run well on one
platform – but the tricks might not work elsewhere
The compiler and runtime system will rarely stop your C
program from doing stupid/bad things
Compile-time type checking is weak
 No run-time checks for array bounds errors, etc. like in Java

QUESTIONS?
Download