01 Intro
01 Intro
c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf(“Welcome to COS 217\n");
printf("Introduction to Programming Systems\n\n");
printf("%s %d\n", "Spring", 2019);
return 0;
}
$ cat Makefile
CC=gcc217
welcome: welcome.o
$ make
gcc217 -c -o welcome.o welcome.c
gcc217 welcome.o -o welcome
$ ./welcome
Welcome to COS 217
Introduction to Programming Systems
Spring, 2019
Agenda
2
Introductions
Lead Instructor
• Prof. Szymon Rusinkiewicz [email protected]
Lead Preceptors
• Robert Dondero, Ph.D. [email protected]
• Xiaoyan Li [email protected]
3
Agenda
4
Goal 1: Programming in the Large
Topics
• Modularity/abstraction, information hiding, resource management,
error handling, testing, debugging, performance improvement,
tool support
5
Goal 2: Under the Hood
Downward tours
language service
Assembly Language levels Operating System levels
tour tour
Machine Language Hardware
6
Modularity!
Goals: Summary
Help you to become a...
Power Programmer!!!
8
Specific Goal: Learn C
9
Specific Goal: Learn Linux
Question: Why use the Linux operating system?
10
Agenda
11
Lectures
Lectures
• Describe material at conceptual (high) level
• Slides available via course website
Etiquette
• Use electronic devices only for taking notes or annotating slides
(but consider taking notes by hand – research shows it works better!)
• No SnapFaceNewsBookInstaGoo, please
iClicker
• Register in Blackboard (not with iClicker – they’ll charge you)
• Occasional questions in class, graded on participation
(with a generous allowance for not being able to attend)
12
iClicker Question
Q: Do you have an iClicker with you today?
A. Yes
Etiquette
• Attend your precept – attendance will be taken
• Must miss your precept? ⇒ inform preceptors & attend another
• Use SCORE to move to another precept
• Trouble ⇒ See Colleen Kenny (CS Bldg 210)
• But Colleen can’t move you into a full precept
14
Website
http://www.cs.princeton.edu/~cos217/
15
Piazza
Piazza
• http://piazza.com/princeton/spring2019/cos217
• Instructions provided in first precept
Piazza etiquette
• Study provided material before posting question
• Lecture slides, precept handouts, required readings
• Read / search all (recent) Piazza threads before posting question
• Don’t reveal your code!
• See course policies
16
Books
C Programming: A Modern Approach
(Second Edition) (required)
• King
• C programming language and standard libraries
See also
• Linux man command
18
Programming Environment
Server Client
SSH
Linux OS
GNU
tools
Your
Program
armlab01
armlab02 On-campus
or
off-campus 19
Agenda
20
Grading
Participation *** 10
21
Programming Assignments
Regular (not-quite-weekly) assignments
0. Introductory survey
1. “De-comment” program
2. String module
3. Symbol table module
4. Assembly language programs
5. Buffer overrun attack
6. Heap manager module
7. Unix shell
*(some individual, some done with a partner from your precept)
23
Policies
Learning is a collaborative activity!
• Discussions with others that help you understand
concepts from class are encouraged
26
Course Schedule
27
Questions?
28
Agenda
29
The C Programming Language
30
Java vs. C: History
This is what
we’re using
Algol
LISP Smalltalk
31
C vs. Java: Design Goals
32
Agenda
33
Building Java Programs
$ javac MyProg.java Java compiler
(machine lang code)
HW (ArmLab)
OS (Linux)
MyProg.java MyProg.class
javac
(Java code) (bytecode)
34
Running Java Programs
$ java MyProg Java interpreter /
“virtual machine”
(machine lang code)
HW (ArmLab)
OS (Linux)
MyProg.class
(bytecode)
35
Building C Programs
$ gcc217 myprog.c –o myprog C “Compiler driver”
(machine lang code)
HW (ArmLab)
OS (Linux)
myprog.c myprog
gcc217
(C code) (machine lang code)
36
Running C Programs
$ ./myprog myprog
(machine lang code)
HW (ArmLab)
OS (Linux)
37
Agenda
38
Java vs. C: Portability
C
• Manual bounds checking
• NULL pointer checking,
• Manual memory management
Java C
Portability + -
Efficiency - +
Safety + -
41
iClicker Question
Q: Which corresponds to the C programming language?
A.
B.
C.
Agenda
43
Java vs. C: Details
44
Java vs. C: Details
Java C
Hello.java: hello.c:
public class Hello #include <stdio.h>
Overall { public static void main
(String[] args) int main(void)
Program
{ System.out.println( { printf("hello, world\n");
Structure return 0;
"hello, world");
} }
}
45
Java vs. C: Details
Java C
Character type char // 16-bit Unicode char /* 8 bits */
byte // 8 bits (unsigned, signed) char
short // 16 bits (unsigned, signed) short
Integral types
int // 32 bits (unsigned, signed) int
long // 64 bits (unsigned, signed) long
float
Floating point float // 32 bits
double
types double // 64 bits
long double
/* no equivalent */
Logical type boolean
/* use 0 and non-0 */
Generic pointer
Object void*
type
#define MAX 1000
Constants final int MAX = 1000; const int MAX = 1000;
enum {MAX = 1000};
46
Java vs. C: Details
Java C
int [] a = new int [10]; int a[10];
Arrays float [][] b = float b[5][20];
new float [5][20];
Array bound
// run-time check /* no run-time check */
checking
// Object reference is an
Pointer type int *p;
// implicit pointer
class Mine struct Mine
{ int x; { int x;
Record type
float y; float y;
} };
47
Java vs. C: Details
Java C
String s1 = "Hello"; char *s1 = "Hello";
Strings String s2 = new char s2[6];
String("hello"); strcpy(s2, "hello");
String s1 + s2 #include <string.h>
concatenation s1 += s2 strcat(s1, s2);
Logical ops * &&, ||, ! &&, ||, !
Relational ops * =, !=, <, >, <=, >= =, !=, <, >, <=, >=
=, +=, -=, *=, /=, %=, =, +=, -=, *=, /=, %=,
Assignment ops
<<=, >>=, >>>=, &=, ^=, |= <<=, >>=, &=, ^=, |=
/* comment */ /* comment */
Comments
// another kind
f(x, y, z);
Method / function
someObject.f(x, y, z); f(x, y, z);
call
SomeClass.f(x, y, z);
int main(void)
{ const double KMETERS_PER_MILE = 1.609;
int miles;
double kMeters;
printf("miles: ");
if (scanf("%d", &miles) != 1)
{ fprintf(stderr, "Error: Expected a number.\n");
exit(EXIT_FAILURE);
}
Course overview
• Introductions
• Course goals
• Goal 1: Learn “programming in the large”
• Goal 2: Look “under the hood”and learn low-level programming
• Use of C and Linux supports both goals
• Resources
• Lectures, precepts, programming environment, Piazza, textbooks
• Course website: access via http://www.cs.princeton.edu
• Grading
• Policies
• Schedule
53
Summary
54
Getting Started
55