Académique Documents
Professionnel Documents
Culture Documents
Instructor: Roded Sharan, roded@post.tau.ac.il TA: Dana Silverbush Course materials: virtual.tau.ac.il
http://www.cs.tau.ac.il/~roded/courses/soft-project12b.html
Course Structure
The C programming language: 8-9 classes including 2 exercises (5%+10%; mandatory) and a final exam (30%). Large project (55%): in pairs, 2 classes will be devoted to its presentation; includes interfacing an integer linear programming library (CPLEX).
Why C ?
C is compact: few reserved words, terse commands, powerful set of operators. C is efficient: direct memory management, some operators directly modify machine registers, manipulation of memory addresses. C is modular and typed. C is the native language of UNIX. Basis of C++ (and Java).
C is also beautiful
main(){char q=34,n=10,*a=" main() {char q=34,n=10,*a=% c% s% c; pr intf(a,q,a,q,n);}% c" ;pr intf(a,q,a,q,n);}
C vs. Java
Java was developed based on C and inherited most of its syntax. Main difference: C is procedural and not objectoriented. Thus, no classes/interfaces; methods are called functions and do not belong to any object. Similar primitive types as in Java, but no boolean and string types; other differences.
C Topics
Lexical elements (Ch. 2) Fundamental data types (Ch. 3) Flow of control (Ch. 4) Functions (Ch. 5); Runtime environment Arrays, pointers and strings (Ch. 6); Dynamic matrix allocation (Ch. 12.6) Bitwise operators (Ch. 7) Preprocessor (Ch. 8) Structures (Ch. 9) Linked lists (Ch. 10) Input/output and files (Ch. 11)
Programming Environment
Unix Make CPLEX
Operating System
Operating system: Manages the available hardware (CPU, memory) and software (editors, development tools) resources. Provides interface for using them by multiple users. Users AUI API OS kernel Hardware Shell: command-line interpreter to interface the OS.
The Unix OS
Unix: multi-user, multi-process OS; open source. History: 1969 Initial version by Thompson & Ritchie at Bell Labs (assembly and later B). 70s Rewritten in C. 80s System-V (AT&T) and BSD (Berkeley) versions. 90s Linux by Linus Torvalds. For basic introduction and commands see web-page.
Project
Task: Clustering via integer linear programming (ILP) Goals:
Large scale programming Efficient computation Real world application (biological networks) Interfacing an external library (CPLEX)
The C System
Keywords Identifiers Constants Operators Punctuation
C
Standard library
edit
hello.c
compile
hello.o
link
hello
Keywords
Reserved words with a strict meaning C does a lot with relatively few keywords.
Identifiers
A token composed of a sequence of letters tax = price * tax_rate First character cannot be a digit!! 5a_cse is not legal Case sensitive CSE_5a is different from cse_5a Some identifiers are already taken: keywords. Choose names that are meaningful (cse_5a is not a good example!!)
Comments
Arbitrary strings placed between the delimiters /* and */. /* * A comment can be written in this fashion * to set it off from the surrounding code. */ For single line comments (do not follow the ANSI standard): // This is a comment in c++
double
long double
Declaration is important for: Memory allocation Interpreting the number correctly within expressions.
Constants
char int long unsigned float double long double a, x, 0, &, \n 1, 0, -54, 4234567 0l, 123l, 7766l 0u, 23u, 3000000000u 1.2f, .2f, 1.f, 3.14159f 1.0, -3.1412, 1.2e-2 1.0l, 2.4433l
48 49 50 ... 57 is printed
Representation
Type
unsigned char unsigned char unsigned char unsigned char unsigned char signed char signed char signed char signed int 0 255 127 128 (2-complement) -1 -128
value
Binary value
vvvv vvvv 0000 1111 0111 1000 svvv 1111 1000 svvv vvvv vvvv vvvv 0000 1111 1111 0000 vvvv 1111 0000 vvvv vvvv vvvv vvvv
v means value
Float Representation
Decimal: Binary: int.frac*10exp 1.frac*2exp
exp+127
Sizeof
sizeof(char) == 1 sizeof(short) <= sizeof(int) <= sizeof(long) sizeof(signed) == sizeof(unsigned) == sizeof(int) sizeof(float) <= sizeof(double) <= sizeof(long double)
Type unsigned float unsigned long long double unsigned long system dependent
Cast
double d = 3.3; int i = 0; unsigned ui = 0; i == 3 i = (int)d; d == 1.5 d = (double)i / 2; ui = (unsigned)i;