COS 217: Introduction To Programming Systems!: Jennifer Rexford!
COS 217: Introduction To Programming Systems!: Jennifer Rexford!
Jennifer Rexford !
Introductions!
" Lectures!
" Jennifer Rexford (Professor)! " [email protected] !
" Preceptors!
" Christopher Moretti (Lead Preceptor)! " [email protected]! " Sibren Isaacman! " [email protected]!
Course Goal 1: Programming in the Large! " Help you learn how to write large # computer programs! " Specically:!
" Write modular code! " Write portable code! " Test and debug your code! " Improve your code$s performance (and when to do so)! " Use tools to support those activities!
Assembly Language!
Operating System!
Machine Language!
Hardware!
Power Programmer!!!!
8
" Precepts!
" Support lectures by describing concepts at a lower level! " Support your work on assignments!
Resources: Books!
" Required book!
" C Programming: A Modern Approach (Second Edition), King, 2008.! " Covers the C programming language and standard libraries!
Resources: Manuals!
" Manuals (for reference only, available online)!
" IA32 Intel Architecture Software Developer's Manual, Volumes 1-3! " Tool Interface Standard & Executable and Linking Format! " Using as, the GNU Assembler !
12
Lab TAs!
13
SSH!
" Notes!
" Other options cannot be used for some assignments (esp. timing studies)! " Instructors cannot promise support of other options! " Strong recommendation: Use Option 1 or 2 for all assignments! " First precept provides setup instructions!
15
Grading!
" Seven programming assignments (50%)!
" Working code! " Clean, readable, maintainable code! " On time (penalties for late submission)! " Final assignment counts double (12.5%)!
16
Programming Assignments!
" Programming assignments!
1." 2." 3." 4." 5." 6." 7." A de-comment program! A string module! A symbol table module ! IA-32 assembly language programs! A buffer overrun attack! A heap manager module! A Unix shell !
" See course Schedule web page for due dates/times! " Advice: Start early to allow time for debugging (especially in the background while you are doing other things!)!
17
18
Course Schedule!
" Very generally!
Weeks! 1-2! 3-6! 6! 7! 8-13! Under the Hood! Lectures! Intro to C (conceptual)! Pgmming in the Large! Precepts! Intro to Linux/GNU# Intro to C (mechanical)! Advanced C!
Midterm Exam ! Recess ! Assembly Language# Pgmming Assignments! Reading Period ! Final Exam !
21
We will use!
1960! BCPL! 1970! B! 1972! C!
LISP!
Smalltalk!
22
24
25
" Good things you can do in C, but (more or less) must do in Java!
" Program using the object-oriented style!
28
C !
Building!
Running!
29
C !
char /* 8 bits */ char short int long
// 32 bits // 64 bits
C !
int a[10]; float b[5][20]; /* no run-time check */ int *p; struct Mine { int x; float y; }
Record type!
31
C !
char *s1 = "Hello"; char s2[6]; strcpy(s2, "hello"); #include <string.h> strcat(s1, s2); &&, ||, ! =, !=, >, <, >=, <= +, -, *, /, %, unary >>, <<, &, |, ^ =, *=, /=, +=, -=, <<=, >>=, =, ^=, |=, %=
String s1 + s2 concatenation! s1 += s2 Logical ops! Arithmetic ops! Bitwise ops! Assignment ops! &&, ||, ! Relational ops! =, !=, >, <, >=, <= +, -, *, /, %, unary >>, <<, >>>, &, |, ^ =, *=, /=, +=, -=, <<=, >>=, >>>=, =, ^=, |=, %=
32
C !
if (i < 0) statement1; else statement2; switch (i) { case 1: ... break; case 2: ... break; default: ... } goto SomeLabel;
33
switch stmt!
goto stmt!
C !
int i; for (i=0; i<10; i++) statement; while (i < 0) statement; do { statement; } while (i < 0); continue; /* no equivalent */ break; /* no equivalent */
34
while stmt!
continue stmt! labeled continue stmt! break stmt! labeled break stmt!
C !
throw, try-catch-finally /* no equivalent */ /* comment */ // another kind f(x, y, z); someObject.f(x, y, z); SomeClass.f(x, y, z); /* comment */
f(x, y, z);
35
Example C Program!
#include <stdio.h> #include <stdlib.h> const double KMETERS_PER_MILE = 1.609; int main(void) { int miles; double kmeters; printf("miles: "); if (scanf("%d", &miles) != 1) { fprintf(stderr, "Error: Expect a number.\n"); exit(EXIT_FAILURE); } kmeters = miles * KMETERS_PER_MILE; printf("%d miles is %f kilometers.\n", miles, kmeters); return 0; }
36
Conclusions!
" Getting started with C!
" C was designed for system programming! " Different design goals from of Java! " Explains many of C$s eccentricities! " Knowing Java gives you a head start at learning C! " C is not object-oriented, but many aspects are similar!
Getting Started!
" Check out course Web site soon!
" Study Policies page! " First assignment is available!
38