INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.
|
|
- Roy Adams
- 6 years ago
- Views:
Transcription
1 C PROGRAMMING 1
2 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2
3 LITTERATURE 3. 1
4 FOR C-PROGRAMMING The C Programming Language (Kernighan and Richie) - The bible, and the book that is referenced in this material. Essential C Online c-course Another online c-course Yet another online c-course
5 FOR VALGRIND Quickstart guide User manual 3. 23
6 FOR MAKEFILE AND DDD Tutorial for makefile Manual for ddd debugger 3. 4
7 GETTING STARTED 4. 1
8 HELLO WORLD hello_world.c # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { p r i n t f ( " H e l l o w o r l d! \ n " ) ; r e t u r n 0 ; } gcc hello_world.c./a.out Compile using: which will generate a.out Run using:
9 COMPILER FLAGS You can (and are recommended to) compile with several flags to the compiler: -g = debug information -Wall = All warnings are displayed -O9 = Optimization gcc -g -Wall hello_world.c Which makes it: 4. 2
10 VARIABLE TYPES char int float double short/long can specify size. signed (use 1 bit for sign)/unsigned const int i = 42; i is not a variable. 4. 3
11 STATIC VARIABLES You can declare a variable static, and if done in global scope, use it inside functions etc. # i n c l u d e < s t d i o. h > s t a t i c i n t i = 0 ; i n t m a i n ( v o i d ) { p r i n t f ( " % i \ n ", i ) ; i = i + 1 ; p r i n t f ( " % i \ n ", i ) ; r e t u r n 0 ; } 4. 4
12 GLOBAL VARIABLES Prefixing variables with extern makes them globally visible from other files
13 STRINGS AND ARRAYS Strings are arrays of char Hello" is the same as char str[] = {'H','e','l','l','o','\0'} We will cover much more on strings when we get to pointers. # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { c h a r s t r [ ] = { ' H ', ' e ', ' l ', ' l ', ' o ', ' \ 0 ' } ; p r i n t f ( " % s - % s \ n ", s t r, " H e l l o " ) ; r e t u r n 0 ; }
14 ENUMS # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { e n u m f i r s t m o n t h s { J A N, F E B, M A R, A P R } ; e n u m l a s t m o n t h s { N O V = 1 0, D E C = 1 1 } ; p r i n t f ( " % i \ n ", J A N ) ; p r i n t f ( " % i \ n ", N O V ) ; r e t u r n 0 ; } All enumerated values must be different, and will start with 0 if not explicitly defined. 4. 7
15 OPERATORS + - * / % 4. 89
16 COMPARISON: < <= > >= ==!= 4. 10
17 LOGIC 0 is false, everything else is true! is used for negation &&is boolean AND is boolean OR
18 BITWISE OPERATORS & is bitwise AND is bitwise OR ^ is bitwise XOR << is left shift 4. 11
19 BITWISE OPERATORS # i n c l u d e < s t d i o. h > s t a t i c u n s i g n e d i n t b i n a r y = 6 ; s t a t i c u n s i g n e d i n t b i n a r y = 2 ; i n t m a i n ( v o i d ) { p r i n t f ( " % i \ n ", b i n a r y & b i n a r y ) ; p r i n t f ( " % i \ n ", b i n a r y b i n a r y ) ; p r i n t f ( " % i \ n ", b i n a r y ^ b i n a r y ) ; p r i n t f ( " % i \ n ", b i n a r y < < 1 ) ; p r i n t f ( " % i \ n ", b i n a r y > > 1 ) ; r e t u r n 0 ; } 4. 12
20 PRINTF Arguments % int/decimal numner %uunsigned number %csingle character %sprints a string %ppointer address 4. 13
21 PRINTF There are more arguments to specify adjustment and width, check the book/manual. If you create a segfault, and you do not use \n with your printf, you are not guaranteed that it is printed!
22 INCREMENT/DECREMENT ++and --can be used both before and after an operator. i++ ++i Increments i after its value is used Increments i before its value is used
23 INCREMENT/DECREMENT # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { i n t i, j, b e f o r e, a f t e r ; i = 0 ; j = 0 ; b e f o r e = + + i ; a f t e r = j + + ; } p r i n t f ( " B : % i A : % i i : % i, j : % i \ n ", b e f o r e, a f t e r, i, j ) ; r e t u r n 0 ; 4. 16
24 CONTROL FLOW Looks like java/python etc
25 LOOPS # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { i n t i ; f o r ( i = 0 ; i < 1 0 ; i + + ) { p r i n t f ( " i : % i \ n ", i ) ; } i = 0 ; w h i l e ( i < 1 0 ) { p r i n t f ( " i : % i \ n ", i ) ; i + + ; }
26 IF/ELSE # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { i n t i ; i = 1 ; i f ( i ) { p r i n t f ( " i f s t a t e m e n t \ n " ) ; } e l s e { p r i n t f ( " e l s e s t a t e m e n t \ n " ) ; } } r e t u r n 0 ; 5. 2
27 SWITCH # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { i n t i ; s w i t c h ( i ) { c a s e 0 : p r i n t f ( " i i s 0 \ n " ) ; b r e a k ; c a s e 1 : p r i n t f ( " i i s 1 \ n " ) ; b r e a k ; d e f a u l t : p r i n t f ( " i i s n o t 0 o r 1 \ n " ) ; b r e a k ; } r e t u r n 0 ; } 5. 3
28 BREAK break can be used in both loops and switches to exit them. continue can only be used in loops, and jumps to the beginning of the loop
29 STYLE COMMENTS A nice c-style guide can be found at Declare all variables of a function before anything else. Including before you assign them any value 5. 6
30 FUNCTIONS, STRUCTS, ETC. 6. 1
31 FUNCTIONS Remember to forward declare functions. If you use a function before it is declared, it is an error. # i n c l u d e < s t d i o. h > / / T h e a d d m e t h o d i s f o r w a r d d e c l a r e d, b e c a u s e i t i s u s e d b e f o r e i t i i n t a d d ( i n t a, i n t b ) ; i n t m a i n ( v o i d ) { i n t i, j ; i = 2 ; j = 3 ; p r i n t f ( " i + j f u n c t i o n s t y l e = % i \ n ", a d d ( i, j ) ) ; r e t u r n 0 ; } i n t a d d ( i n t a, i n t b ) { r e t u r n a + b ; }
32 # i n c l u d e < s t d i o. h > RECURSIVE FUNCTIONS i n t f a c t o r i a l ( i n t i ) ; Notice again the forward declaration i n t m a i n ( v o i d ) { p r i n t f ( " 5! = % i \ n ", f a c t o r i a l ( 5 ) ) ; r e t u r n 0 ; } i n t f a c t o r i a l ( i n t i ) { i f ( i = = 0 ) { r e t u r n 1 ; } r e t u r n i * f a c t o r i a l ( i - 1 ) ; } 6. 2
33 HEADER FILES/INCLUDING OTHER FILES To divide code into logical parts, you can split it across multiple (pair of) files. The function declarations, defined variables, structs etc. (think the public stuff), is declared in a header file, ending with.h. The implementation is kept in a code file, ending with.c 6. 3
34 INCLUDING HEADER FILES Both user and system header files are included using the preprocessing directive `#include `. It has following two forms: #include <file> This form is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code. #include "file" This form is used for header files of your own program. It searches for a file named file in the directory containing the current file. You can prepend directories to this list with the
35 I option while compiling your source code. ONCE-ONLY HEADERS If a header file happens to be included twice, the compiler will process its contents twice and will result an error. The standard way to prevent this is to enclose the entire real contents of the file in a conditional, like this: # i f n d e f H E A D E R _ F I L E # d e f i n e H E A D E R _ F I L E t h e e n t i r e h e a d e r f i l e f i l e # e n d i f This construct is commonly known as a wrapper #ifndef. When the header is included again, the conditional will be false, because HEADER_FILEis defined. The preprocessor will skip over the entire contents of the 6. 5
36 file, and the compiler will not see it twice.
37 STRUCTS A Struct is a group of variables, that belong togeather in a logical way. # i n c l u d e < s t d i o. h > s t r u c t A c c o u n t { d o u b l e a m o u n t ; i n t a c c o u n t _ i d ; } ; i n t m a i n ( v o i d ) { s t r u c t A c c o u n t a c c o u n t ; a c c o u n t. a c c o u n t _ i d = ; a c c o u n t. a m o u n t = ; p r i n t f ( " A c c i d % i a m o u n t : % g \ n ", a c c o u n t. a c c o u n t _ i d, a c c o u n t. a m o u / / U g l y s h o r t c u t - o r d e r i n g m a t t e r s. s t r u c t A c c o u n t a c c o u n t 2 = { , } ; p r i n t f ( " A c c. i d % i a m o u n t : % g \ n ", a c c o u n t 2. a c c o u n t _ i d, a c c o u n t 2. a 6. 6
38 TYPEDEF To avoid typing struct a lot of times, it is common to use typedef # i n c l u d e < s t d i o. h > t y p e d e f s t r u c t _ a c c o u n t { d o u b l e a m o u n t ; i n t a c c o u n t _ i d ; } a c c o u n t ; i n t m a i n ( v o i d ) { a c c o u n t a c c ; a c c. a c c o u n t _ i d = ; a c c. a m o u n t = ; } p r i n t f ( " A c c o u n t i d % i a m o u n t : % g \ n ", a c c. a c c o u n t _ i d, a c c. a m o u n t ) ; r e t u r n 0 ; 6. 7
39 UNION In datastructures etc. you sometimes need to use one or another set of variables. A union only uses space like the biggest of the sets # i n c l u d e < s t d i o. h > u n i o n C a r d { / * P l a y i n g c a r d * / i n t v a l u e ; c h a r f a c e [ 8 ] ; / / T r y u s i n g 9 - e x p l a i n } ; i n t m a i n ( v o i d ) { u n i o n C a r d c a r d 1 ; u n i o n C a r d c a r d 2 ; c a r d 1. v a l u e = 5 ; c a r d 2. f a c e [ 0 ] = ' Q ' ; c a r d 2. f a c e [ 1 ] = ' u ' ; c a r d 2. f a c e [ 2 ] = ' e ' ; c a r d 2. f a c e [ 3 ] = ' e ' ; c a r d 2. f a c e [ 4 ] = ' n ' ; c a r d 2. f a c e [ 5 ] = ' \ 0 ' ; p r i n t f ( " C a r d 1 : % i C a r d 2 % s \ n ", c a r d 1. v a l u e, c a r d 2. f a c e ) ; p r i n t f ( " M e m : % l i = % l i \ n ", s i z e o f ( c a r d 1 ), s i z e o f ( c a r d 2 ) ) ; p r i n t f ( " C a r d 1 : % s C a r d 2 % i \ n ", c a r d 1. f a c e, c a r d 2. v a l u e ) ; r e t u r n 0 ; } 6. 8
40 DEFINES Defines are inserted before the code is compiled. # i n c l u d e < s t d i o. h > # d e f i n e V A L U E 4 2 # d e f i n e D I V ( a, b ) ( a ) / ( b ) i n t m a i n ( v o i d ) { p r i n t f ( " V a l u e : % i \ n ", V A L U E ) ; p r i n t f ( " D I V ( 6, 3 ) : % i \ n ", D I V ( 6, 3 ) ) ; } r e t u r n 0 ; 6. 9
41 POINTERS AND ARRAYS
42 POINTERS Every variable is located somewhere in memory, and thus have an adress where it is located. A pointer is a variable, that is an adress of another variable. A pointer is defined with a star in from of the variable name: int *pointer; You can declare more pointers on the same line, but the star must be with each variable: int *pointer, *also_pointer; To get the adress of a variable, you can use the & operator
43 POINTERS The following example is commented for the operators used with pointers # i n c l u d e < s t d i o. h > i n t m a i n ( v o i d ) { i n t x = 4 2 ; / * A n o r m a l i n t e g e r * / i n t * p ; / * A p o i n t e r t o a n i n t e g e r ( " * p " i s i n t e g e r, s o p m u s t b e a p o i n t e r t o a n i n t e g e r ) * / p = & x ; / * A s s i g n t h e a d d r e s s o f x t o p * / p r i n t f ( " x h a s v a l u e % i \ n ", x ) ; p r i n t f ( " I t s a d d r e s s i s % p \ n ", p ) ; } / * N o t e t h e u s e o f t h e * t o g e t t h e v a l u e * / p r i n t f ( " U s i n g p o i n t e r i, t h e v a l u e o f x : % i \ n ", * p ) ; r e t u r n 0 ; 7. 2
44 POINTERS In this example, the value of i is changed by change() even through it does not have i in its scope # i n c l u d e < s t d i o. h > v o i d c h a n g e ( i n t * p o i n t e r ) { * p o i n t e r = 4 2 ; } i n t m a i n ( v o i d ) { i n t i = 2 ; c h a n g e ( & i ) ; p r i n t f ( " i : % i \ n ", i ) ; r e t u r n 0 ; } 7. 3
45 POINTERS WITH STRUCTS The arrow: is a shorthand notation, for retrieving values from a struct pointer # i n c l u d e < s t d i o. h > # i n c l u d e < s t d l i b. h > t y p e d e f s t r u c t _ A c c o u n t { d o u b l e a m o u n t ; i n t a c c o u n t _ i d ; } A c c o u n t ; i n t m a i n ( v o i d ) { A c c o u n t a c c o u n t ; A c c o u n t * a c c P o i n t e r ; a c c o u n t. a c c o u n t _ i d = ; a c c o u n t. a m o u n t = ; a c c P o i n t e r = & a c c o u n t ; p r i n t f ( " a m o u n t : % g \ n ", ( * a c c P o i n t e r ). a m o u n t ) ; p r i n t f ( " a m o u n t : % g \ n ", a c c P o i n t e r - > a m o u n t ) ; r e t u r n E X I T _ S U C C E S S ; } 7. 4
46 ARRAYS REVISITED Arrays are just pointers to its first element! The following is therefore equivalent Array access arr[0] Table 1. Table title Pointer access *arr arr[2] *(arr + 2) arr[n] *(arr + n) 7. 5
47 MEMORY HANDLING AND I/O
48 MEMORY HANDLING Local variables are placed in the Stack part of memory, and are only valid in the scope of the method. Once a method has returned, the memory is no longer available for that variable. For more permanent location, memory must be allocated on the heap. For this you can use the void *malloc(int num);function. It allocates an array of num bytes and leave them initialized. When the memory is no longer needed, you can use free() to hand it back to the operating system.
49 MEMORY HANDLING (1) # i n c l u d e < s t d i o. h > # i n c l u d e < s t d l i b. h > # i n c l u d e < s t r i n g. h > i n t m a i n ( v o i d ) { c h a r s t r i n g 1 [ ] ; c h a r * s t r i n g 2 ; ( 1 ) } r e t u r n E X I T _ S U C C E S S ; 1 See next slide 8. 2
50 MEMORY HANDLING (1) / / U s i n g a s t r i n g c o p y f u n c t i o n s t r c p y ( s t r i n g 1, " I ' m a n a r r a y, m e m o r y o n s t a c k " ) ; / * a l l o c a t e m e m o r y d y n a m i c a l l y * / s t r i n g 2 = m a l l o c ( * s i z e o f ( c h a r ) ) ; / / I f m a l l o c r e t u r n s N U L L, s o m e t h i n g w e n t w r o n g ( o u t o f m e m o r y ) i f ( s t r i n g 2 = = N U L L ) { / / f p r i n t f : O u t p u t w r i t t e n t o s t r e a m, h e r e : s t d e r r o r f p r i n t f ( s t d e r r, " E r r o r : u n a b l e t o a l l o c a t e r e q u i r e d m e m o r y \ n " ) ; } e l s e { s t r c p y ( s t r i n g 2, " I ' m n o w s t o r i n g d a t a o n t h e h e a p " ) ; } p r i n t f ( " s t r i n g 1 = % s \ n ", s t r i n g 1 ) ; p r i n t f ( " s t r i n g 2 = % s \ n ", s t r i n g 2 ) ; / / I ' m d o n e u s i n g t h e m e m o r y - h a n d i t b a c k n i c e l y f r e e ( s t r i n g 2 ) ; 8. 3
51 READING/WRITING FILES C communicates with files using a new datatype called a file pointer. This type is defined within stdio.h, and written as FILE *. A file pointer called input_file is declared in a statement like FILE *input_file; 8. 4
52 READING/WRITING FILES To open aa file, you use fopen(filename, mode). The mode can be one of the following: ropen file for reading wopen file for writing aopen file for appending You close a file using fclose(file);. There is a limit of open files on a system, and it is bad style to not close a file after use. 8. 5
53 READING FILES To read and write input, there are various methods, but an easy one for reading is: char *fgets( char *buf, int n, FILE *fp ); The functions fgets()reads up to n-1 characters from the input stream referenced by fp. It copies the read string into the buffer buf, appending a null character to terminate the string. If this function encounters a newline character '\n' or the end of the file EOF before they have read the maximum number of characters, then it returns only the characters read up to that point including new line character. 8. 6
54 READING FILES Notice that stdin, stdout, stderr all are filepointers, but they are always open, and do not need to be opened with fopen
55 WRITING FILES For writing, the equivalent is: int fputs( const char *s, FILE *fp ); The function fputs()writes the string s to the output stream referenced by fp. It returns a non-negative value on success, otherwise EOF is returned in case of any error.
56 WRITING FILES # i n c l u d e < s t d i o. h > # i n c l u d e < s t d l i b. h > # i n c l u d e < s t r i n g. h > i n t f i l e _ c o p y ( c h a r * f i l e n a m e _ i n, c h a r * f i l e n a m e _ o u t ) ; i n t m a i n ( v o i d ) { r e t u r n f i l e _ c o p y ( ". / t e s t. t x t ", ". / c o p i e d. t x t " ) ; } i n t f i l e _ c o p y ( c h a r * f i l e n a m e _ i n, c h a r * f i l e n a m e _ o u t ) { F I L E * i n f i l e ; F I L E * o u t f i l e ; c h a r l i n e [ ] ; ( 1 ) ( 2 ) r e t u r n E X I T _ S U C C E S S ; } 1 See next slide 2 See the following slide 8. 9
57 WRITING FILES i n f i l e = f o p e n ( f i l e n a m e _ i n, " r " ) ; i f (! i n f i l e ) { f p r i n t f ( s t d e r r, " C o u l d n o t o p e n i n p u t f i l e " ) ; r e t u r n E X I T _ F A I L U R E ; } o u t f i l e = f o p e n ( f i l e n a m e _ o u t, " w " ) ; i f (! o u t f i l e ) { f c l o s e ( i n f i l e ) ; f p r i n t f ( s t d e r r, " C o u l d n o t o p e n o u t p u t f i l e " ) ; r e t u r n E X I T _ F A I L U R E ; } 8. 10
58 WRITING FILES w h i l e ( f g e t s ( l i n e, 2 5 6, i n f i l e ) ) { p r i n t f ( " C o p y i n g t h e l i n e : ' % s ' ", l i n e ) ; f p u t s ( l i n e, o u t f i l e ) ; } f c l o s e ( i n f i l e ) ; f c l o s e ( o u t f i l e ) ; If you prefer to read one char at a time, fgetcand fputc can be used 8. 11
59 SORTING AN ARRAY The build in function qsortcan be used for this. # i n c l u d e < s t d i o. h > # i n c l u d e < s t d l i b. h > e n u m s u i t s { D I A M O N D S, H E A R T S, S P A D E S, C L U B S } ; t y p e d e f s t r u c t _ C a r d { / * P l a y i n g c a r d * / i n t v a l u e ; i n t s u i t ; } C a r d ; c h a r * g e t S u i t ( i n t s u i t ) { s w i t c h ( s u i t ) { c a s e D I A M O N D S : r e t u r n " D i a m o n d s " ; c a s e H E A R T S : r e t u r n " H e a r t s " ; c a s e C L U B S : r e t u r n " C l u b s " ; c a s e S P A D E S : r e t u r n " S p a d e s " ; } r e t u r n N U L L ; } 1 See following slides 8. 12
60 SORTING AN ARRAY Make a comparator function i n t c o m p a r e C a r d s ( C a r d * * c 1, C a r d * * c 2 ) { i f ( ( * c 1 ) - > v a l u e = = ( * c 2 ) - > v a l u e ) { r e t u r n ( * c 1 ) - > s u i t - ( * c 2 ) - > s u i t ; } r e t u r n ( * c 1 ) - > v a l u e - ( * c 2 ) - > v a l u e ; }
61 SORTING AN ARRAY i n t m a i n ( v o i d ) { i n t i, j ; C a r d * d e c k [ 5 2 ] ; } / / F i l l a r r a y w i t h d e c k o f c a r d s f o r ( i = 0 ; i < 4 ; i + + ) { f o r ( j = 0 ; j < 1 3 ; j + + ) { d e c k [ i * j ] = m a l l o c ( s i z e o f ( C a r d ) ) ; d e c k [ i * j ] - > v a l u e = 1 + j ; d e c k [ i * j ] - > s u i t = i ; } } ( 1 ) r e t u r n 0 ;
62 SORTING AN ARRAY / / P r i n t a l l c a r d s f o r ( i = 0 ; i < 5 2 ; i + + ) { p r i n t f ( " S u i t : % s, v a l u e : % i \ n ", g e t S u i t ( d e c k [ i ] - > s u i t ), d e c k [ i ] - > } / / W i s h s o r t e d b y ( v a l u e, d e c k ) p r i n t f ( " \ n S o r t i n g! \ n \ n " ) ; q s o r t ( d e c k, 5 2, s i z e o f ( C a r d * ), ( i n t ( * ) ( c o n s t v o i d *, c o n s t v o i d * ) ) / / P r i n t a l l c a r d s f o r ( i = 0 ; i < 5 2 ; i + + ) { p r i n t f ( " S u i t : % s, v a l u e : % i \ n ", g e t S u i t ( d e c k [ i ] - > s u i t ), d e c k [ i ] - > } 8. 15
63 MAKEFILE
64 MAKEFILE WHY? Checks timestamps to see what has changed and rebuilds just what you need, without wasting time rebuilding other files. Manage Several source files and compile them quickly with a single Command Line. Make layers a rich collection of options that lets you manipulate multiple directories, build different versions of programs for different platforms, and customize your builds in other ways.
65 MAKE UTILITY If you run make This will cause the make program to read the Makefile and build the first target it finds there. If you have several makefiles, then you can execute them with the command: make -f mymakefile For more options use: man make 9. 2
66 HOW DOES IT WORK? Typically the default goal in most makefiles is to build a program. This usually involves many steps: 1. Generate the source code using some utilities like Flex & Bison. 2. Compile the source code into binary file (.o files c/c++/java etc.) 3. bound the Object files together using a linker( gcc/g++) to form an executable program 9. 3
67 MAKEFILE STRUCTURE Makefiles contain definitions and rules. A definition has the form: VAR=value A rule has the form: output files: input files commands to turn inputs to outputs All commands must be tab-indented. To reference the variable VAR, surround it with $(VAR). 9. 4
68 RULES Makefile contains a set of rules used to build an application. The first rule (default rule) seen by make consists of three parts: 1. The Target. 2. The Dependencies. 3. The Command to be performed. 9. 5
69 HOW TO MAKE A SIMPLE MAKEFILE Here s a simple example for a C program that defines foo() in foo.c, but uses it in bar.c. C C = g c c b a r : b a r. c f o o. h f o o. o $ ( C C ) - o b a r b a r. c f o o. o f o o. o : f o o. c f o o. h $ ( C C ) - c f o o. c r u n : c l e a n :. / b a r r m - f b a r f o o. o 9. 6
70 CONVENTIONS It s common to include pseudo-targets in makefiles to automate other parts of the development process. make clean The rule for clean in the previous example doesn t build a file called clean. Rather, it deletes all of the build targets to allow a fresh build from scratch. Including a clean rule is a common convention for make. make test Running make test often runs the test suite for the software. make install Running make install typically installs the compiled binary in a PATH-accessible location. 9. 7
71 For software using the autoconf toolchain, the installation directory is set by running./configure command prior to using make. make run For simple programs, make run acts like an alias to the compiled binary.
72 VALGRIND
73 VALGRIND The Valgrind tool suite provides a number of debugging and profiling tools that help you make your programs faster and more correct. The most popular of these tools is called Memcheck. It can detect many memory-related errors that are common in C and C++ programs and that can lead to crashes and unpredictable behaviour.
74 PREPARTION Compile your program with -gto include debugging information so that Memcheck s error messages include exact line numbers. Using -O0is also a good idea With -O1line numbers in error messages can be inaccurate Use of -O2and above is not recommended as Memcheck occasionally reports uninitialised-value errors which don t really exist
75 RUNNING MEMCHECK If you normally run your program like this:./myprog arg1 arg2 Use this command line: valgrind --leak-check=yes./myprog arg1 arg2 Memcheck is the default tool. The --leak-check option turns on the detailed memory leak detector
76 CAVEATS Memcheck is not perfect; it occasionally produces false positives
77 DEBUGGING - DDD 11. 1
78 DEBUGGING - DDD DDD is a graphical front-end for GDB and other commandline debuggers
79 DDD Run from command line ddd Must compile programs with -gflag to get debug information included 11. 3
80 USAGE Step through a program Use breakpoints See values of viariables 11. 4
81 QUESTIONS 12
ITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!
More informationComp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40
Comp 11 Lectures Mike Shah Tufts University July 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 26, 2017 1 / 40 Please do not distribute or host these slides without prior permission. Mike
More informationITI Introduction to Computing II
(with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!
More informationMiniMat: Matrix Language in OCaml LLVM
Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................
More informationProgramsystemkonstruktion med C++: Övning 1. Karl Palmskog Translated by: Siavash Soleimanifard. September 2011
Programsystemkonstruktion med C++: Övning 1 Karl Palmskog palmskog@kth.se Translated by: Siavash Soleimanifard September 2011 Programuppbyggnad Klassens uppbyggnad A C++ class consists of a declaration
More informationComputer Science Introductory Course MSc - Introduction to Java
Computer Science Introductory Course MSc - Introduction to Java Lecture 1: Diving into java Pablo Oliveira ENST Outline 1 Introduction 2 Primitive types 3 Operators 4 5 Control Flow
More informationDARN: A Matrix Manipulation Language
DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4
More informationECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University
ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Prof. Sunil P Khatri (Lab exercise created and tested by Ramu Endluri, He Zhou and Sunil P
More informationE23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101
E23: Hotel Management System Author: 1302509 Zhao Ruimin 1301478 Wen Yunlu 1302575 Hu Xing 1301911 Chen Ke 1302599 Tang Haoyuan Module: EEE 101 Lecturer: Date: Dr.Lin December/22/2014 Contents Contents
More informationCS Exam 1 Study Guide and Practice Exam
CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................
More informationAntonio Falabella. 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, September 2015, Hamburg
INFN - CNAF (Bologna) 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, 14-25 September 2015, Hamburg 1 / 44 Overview 1 2 3 4 5 2 / 44 to Computing The
More informationComp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33
Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike
More informationFoundations of Computation
The Australian National University Semester 2, 2018 Research School of Computer Science Tutorial 1 Dirk Pattinson Foundations of Computation The tutorial contains a number of exercises designed for the
More informationimport java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ;
CPSC 490 Input Input will always arrive on stdin. You may assume input is well-formed with respect to the problem specification; inappropriate input (e.g. text where a number was specified, number out
More informationEDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach
EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types
More informationOutline. policies for the first part. with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014
Outline 1 midterm exam on Friday 11 July 2014 policies for the first part 2 questions with some potential answers... MCS 260 Lecture 10.0 Introduction to Computer Science Jan Verschelde, 9 July 2014 Intro
More informationNotater: INF3331. Veronika Heimsbakk December 4, Introduction 3
Notater: INF3331 Veronika Heimsbakk veronahe@student.matnat.uio.no December 4, 2013 Contents 1 Introduction 3 2 Bash 3 2.1 Variables.............................. 3 2.2 Loops...............................
More informationCS429: Computer Organization and Architecture
CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 3, 2014 at 08:38 CS429 Slideset C: 1
More informationCOMS 6100 Class Notes
COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran
More informationCS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18
CS 7B - Spring 2018 - Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 Background Theory A bitwise number is a number in base 2. In base 2, place values are either a 1 or 0, depending
More informationLexical Analysis: DFA Minimization & Wrap Up
Lexical Analysis: DFA Minimization & Wrap Up Automating Scanner Construction PREVIOUSLY RE NFA (Thompson s construction) Build an NFA for each term Combine them with -moves NFA DFA (subset construction)
More informationComp 11 Lectures. Dr. Mike Shah. August 9, Tufts University. Dr. Mike Shah (Tufts University) Comp 11 Lectures August 9, / 34
Comp 11 Lectures Dr. Mike Shah Tufts University August 9, 2017 Dr. Mike Shah (Tufts University) Comp 11 Lectures August 9, 2017 1 / 34 Please do not distribute or host these slides without prior permission.
More informationIntroduction to Programming (Java) 3/12
Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University
ECEN 651: Microprogrammed Control of Digital Systems Department of Electrical and Computer Engineering Texas A&M University Prof. Mi Lu TA: Ehsan Rohani Laboratory Exercise #4 MIPS Assembly and Simulation
More informationIntroduction to ANTLR (ANother Tool for Language Recognition)
Introduction to ANTLR (ANother Tool for Language Recognition) Jon Eyolfson University of Waterloo September 27 - October 1, 2010 Outline Introduction Usage Example Demonstration Conclusion Jon Eyolfson
More informationVerified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017
Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 CakeML Has: references, modules, datatypes, exceptions, a FFI,... Doesn t have:
More informationThe Pip Project. PLT (W4115) Fall Frank Wallingford
The Pip Project PLT (W4115) Fall 2008 Frank Wallingford (frw2106@columbia.edu) Contents 1 Introduction 4 2 Original Proposal 5 2.1 Introduction....................................................... 5
More information1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;
1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).
More informationScripting Languages Fast development, extensible programs
Scripting Languages Fast development, extensible programs Devert Alexandre School of Software Engineering of USTC November 30, 2012 Slide 1/60 Table of Contents 1 Introduction 2 Dynamic languages A Python
More informationElementary Sorts 1 / 18
Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the
More informationCompA - Complex Analyzer
CompA - Complex Analyzer Xiping Liu(xl2639), Jianshuo Qiu(jq2253), Tianwu Wang(tw2576), Yingshuang Zheng(yz3083), Zhanpeng Su(zs2329) Septembee 25, 2017 1 Introduction The motivation for writing this language
More informationAn Introduction to Z3
An Introduction to Z3 Huixing Fang National Trusted Embedded Software Engineering Technology Research Center April 12, 2017 Outline 1 SMT 2 Z3 Huixing Fang (ECNU) An Introduction to Z3 April 12, 2017 2
More informationFunctional Programming with F# Overview and Basic Concepts
Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference
More informationPython. chrysn
Python chrysn 2008-09-25 Introduction Structure, Language & Syntax Strengths & Weaknesses Introduction Structure, Language & Syntax Strengths & Weaknesses Python Python is an interpreted,
More informationLexical Analysis Part II: Constructing a Scanner from Regular Expressions
Lexical Analysis Part II: Constructing a Scanner from Regular Expressions CS434 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper, Ken Kennedy
More informationNumerical differentiation
Chapter 3 Numerical differentiation 3.1 Introduction Numerical integration and differentiation are some of the most frequently needed methods in computational physics. Quite often we are confronted with
More informationAdministrivia. Course Objectives. Overview. Lecture Notes Week markem/cs333/ 2. Staff. 3. Prerequisites. 4. Grading. 1. Theory and application
Administrivia 1. markem/cs333/ 2. Staff 3. Prerequisites 4. Grading Course Objectives 1. Theory and application 2. Benefits 3. Labs TAs Overview 1. What is a computer system? CPU PC ALU System bus Memory
More informationBasic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University
Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic
More informationLisp Introduction. Dr. Neil T. Dantam. Spring CSCI-498/598 RPM, Colorado School of Mines. Dantam (Mines CSCI, RPM) Lisp Spring / 88
Lisp Introduction Dr. Neil T. Dantam CSCI-498/598 RPM, Colorado School of Mines Spring 28 Dantam (Mines CSCI, RPM) Lisp Spring 28 / 88 Outline Lisp Common Lisp by Example Implementation Details Typing
More informationSupplementary Material
Supplementary Material Contents 1 Keywords of GQL 2 2 The GQL grammar 3 3 THE GQL user guide 4 3.1 The environment........................................... 4 3.2 GQL projects.............................................
More informationHow to Make or Plot a Graph or Chart in Excel
This is a complete video tutorial on How to Make or Plot a Graph or Chart in Excel. To make complex chart like Gantt Chart, you have know the basic principles of making a chart. Though I have used Excel
More informationMore on Methods and Encapsulation
More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local
More informationR: A Quick Reference
R: A Quick Reference Colorado Reed January 17, 2012 Contents 1 Basics 2 1.1 Arrays and Matrices....................... 2 1.2 Lists................................ 3 1.3 Loading Packages.........................
More informationMotivation. Dictionaries. Direct Addressing. CSE 680 Prof. Roger Crawfis
Motivation Introduction to Algorithms Hash Tables CSE 680 Prof. Roger Crawfis Arrays provide an indirect way to access a set. Many times we need an association between two sets, or a set of keys and associated
More informationLists, Stacks, and Queues (plus Priority Queues)
Lists, Stacks, and Queues (plus Priority Queues) The structures lists, stacks, and queues are composed of similar elements with different operations. Likewise, with mathematics: (Z, +, 0) vs. (Z,, 1) List
More informationA Short Introduction to Hoare Logic
A Short Introduction to Hoare Logic Supratik Chakraborty I.I.T. Bombay June 23, 2008 Supratik Chakraborty (I.I.T. Bombay) A Short Introduction to Hoare Logic June 23, 2008 1 / 34 Motivation Assertion checking
More informationRobust Programs with Filtered Iterators
Robust Programs with Filtered Iterators Jiasi Shen, Martin Rinard MIT EECS & CSAIL 1 Standard Scenario Input file Program Output 2 Structured Input Units Input Input unit Input unit Input unit unit Program
More informationENS Lyon Camp. Day 5. Basic group. C October
ENS Lyon Camp. Day 5. Basic group. C++. 30 October Contents 1 Input/Output 1 1.1 C-style.......................................... 1 1. C++-style........................................ Stack Overflow
More informationPetriScript Reference Manual 1.0. Alexandre Hamez Xavier Renault
PetriScript Reference Manual.0 Alexandre Hamez Xavier Renault Contents PetriScript basics 3. Using PetriScript................................. 3.2 Generalities.................................... 4.3
More informationPython & Numpy A tutorial
Python & Numpy A tutorial Devert Alexandre School of Software Engineering of USTC 13 February 2012 Slide 1/38 Table of Contents 1 Why Python & Numpy 2 First steps with Python 3 Fun with lists 4 Quick tour
More informationENTROPY the new vision. Zdeněk Breitenbacher
ENTROPY the new vision Zdeněk Breitenbacher zdenek.breitenbacher@avg.com Hello, I am a clean file! and I am the virus, appended to you! and here are my colleagues! Oh no! They are infected too! Fortunately,
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationStatic Program Analysis
Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem
More informationSoftwaretechnik. Lecture 13: Design by Contract. Peter Thiemann University of Freiburg, Germany
Softwaretechnik Lecture 13: Design by Contract Peter Thiemann University of Freiburg, Germany 25.06.2012 Table of Contents Design by Contract Contracts for Procedural Programs Contracts for Object-Oriented
More informationSearching, mainly via Hash tables
Data structures and algorithms Part 11 Searching, mainly via Hash tables Petr Felkel 26.1.2007 Topics Searching Hashing Hash function Resolving collisions Hashing with chaining Open addressing Linear Probing
More informationOn ZK-Crypt, Book Stack, and Statistical Tests
On ZK-Crypt, Book Stack, and Statistical Tests S. Doroshenko A. Fionov A. Lubkin V. Monarev B. Ryabko Abstract The algorithms submitted to the ECRYPT Stream Cipher Project (estream) were tested using the
More information1. Write a program to calculate distance traveled by light
G. H. R a i s o n i C o l l e g e O f E n g i n e e r i n g D i g d o h H i l l s, H i n g n a R o a d, N a g p u r D e p a r t m e n t O f C o m p u t e r S c i e n c e & E n g g P r a c t i c a l M a
More information1 Classical Propositional Logic [20 points]
Homework 1 Solutions 15-414/614 : Bug Catching, Spring 2014 1 Classical Propositional Logic [20 points] Let x, y and z be three propositions. (a) (8 points) Show that the two propositional formulas, (x
More informationBlocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012)
1 Streams Blocking Synchronization: Streams Vijay Saraswat (Dec 10, 2012) Streams provide a very simple abstraction for determinate parallel computation. The intuition for streams is already present in
More informationAnatomy of SINGULAR talk at p. 1
Anatomy of SINGULAR talk at MaGiX@LIX 2011- p. 1 Anatomy of SINGULAR talk at MaGiX@LIX 2011 - Hans Schönemann hannes@mathematik.uni-kl.de Department of Mathematics University of Kaiserslautern Anatomy
More informationOn my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work
Lab 5 : Linking Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The main objective of this lab is to experiment
More informationFunctional Big-step Semantics
Functional Big-step Semantics FM talk, 11 Mar 2015 Magnus Myréen Books Big-step semantics are defined as inductively defined relation. Functions are better! me Context: CakeML verified compiler Old compiler:
More informationTuring Machine Recap
Turing Machine Recap DFA with (infinite) tape. One move: read, write, move, change state. High-level Points Church-Turing thesis: TMs are the most general computing devices. So far no counter example Every
More informationCSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019
CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis
More information6.001 Recitation 22: Streams
6.001 Recitation 22: Streams RI: Gerald Dalley, dalleyg@mit.edu, 4 May 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ The three chief virtues of a programmer are: Laziness, Impatience and Hubris
More informationMore About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010
More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p
More information1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal
Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving
More informationFACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING OBJECT ORIENTED PROGRAMMING DATE 07/2014 SESSION 8:00-10:00
FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CAMPUS CSC2A10 OBJECT ORIENTED PROGRAMMING AUCKLAND PARK CAMPUS (APK) EXAM JULY 2014 DATE 07/2014 SESSION 8:00-10:00 ASSESOR(S)
More information1 Definition of a Turing machine
Introduction to Algorithms Notes on Turing Machines CS 4820, Spring 2017 April 10 24, 2017 1 Definition of a Turing machine Turing machines are an abstract model of computation. They provide a precise,
More informationTuring Machines Part II
Turing Machines Part II Problem Set Set Five Five due due in in the the box box up up front front using using a late late day. day. Hello Hello Condensed Slide Slide Readers! Readers! This This lecture
More information10:00 12:30. Do not open this problem booklet until the start of the examination is announced.
21 I 20 8 26 10:00 12:30 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 4.. Answer the following 4 problems. Use the designated answer sheet for each problem.
More informationProgram verification. Hoare triples. Assertional semantics (cont) Example: Semantics of assignment. Assertional semantics of a program
Program verification Assertional semantics of a program Meaning of a program: relation between its inputs and outputs; specified by input assertions (pre-conditions) and output assertions (post-conditions)
More informationAssignment 4: Object creation
Assignment 4: Object creation ETH Zurich Hand-out: 13 November 2006 Due: 21 November 2006 Copyright FarWorks, Inc. Gary Larson 1 Summary Today you are going to create a stand-alone program. How to create
More informationGRIDLang. Move-Driven Game Programming Language Final Report. May 10, 2017
GRIDLang Move-Driven Game Programming Language Final Report Akshay Nagpal (an2756) Parth Panchmatia (psp2137) Dhruv Shekhawat (ds3512) Sagar Damani (ssd2144) May 10, 2017 1 Contents 1 Introduction 4 2
More informationA GUI FOR EVOLVE ZAMS
A GUI FOR EVOLVE ZAMS D. R. Schlegel Computer Science Department Here the early work on a new user interface for the Evolve ZAMS stellar evolution code is presented. The initial goal of this project is
More informationCS1800: Hex & Logic. Professor Kevin Gold
CS1800: Hex & Logic Professor Kevin Gold Reviewing Last Time: Binary Last time, we saw that arbitrary numbers can be represented in binary. Each place in a binary number stands for a different power of
More informationConstructors - Cont. must be distinguished by the number or type of their arguments.
Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments.
More informationAlgorithms for Data Science
Algorithms for Data Science CSOR W4246 Eleni Drinea Computer Science Department Columbia University Tuesday, December 1, 2015 Outline 1 Recap Balls and bins 2 On randomized algorithms 3 Saving space: hashing-based
More informationProblem Decomposition: One Professor s Approach to Coding
Problem Decomposition: One Professor s Approach to Coding zombie[1] zombie[3] Fewer Buuuuugs zombie[4] zombie[2] zombie[5] zombie[0] Fundamentals of Computer Science I Overview Problem Solving Understand
More informationGoogle Go illustrated on the basis of Fibonacci numbers
Google Go illustrated on the basis of Fibonacci numbers Jan Pennekamp RWTH University Aachen Chair for Data Management and Data Exploration Prof. Dr. T. Seidl Supervision: Dipl.-Ing. Marwan Hassani Friday,
More informationDoc112: Hardware. Department of Computing, Imperial College London. Doc112: Hardware Lecture 1 Slide 1
Doc112: Hardware Department of Computing, Imperial College London Doc112: Hardware Lecture 1 Slide 1 First Year Computer Hardware Course Lecturers Duncan Gillies Bjoern Schuller Doc112: Hardware Lecture
More informationwhere Q is a finite set of states
Space Complexity So far most of our theoretical investigation on the performances of the various algorithms considered has focused on time. Another important dynamic complexity measure that can be associated
More informationCS 163/164 - Exam 1 Study Guide and Practice Exam
CS 163/164 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Strings...................................................
More informationDiscrete Mathematics and Its Applications
Discrete Mathematics and Its Applications Lecture 1: Proposition logic MING GAO DASE @ ECNU (for course related communications) mgao@dase.ecnu.edu.cn Sep. 12, 2017 Outline 1 Propositions 2 Connectives
More informationComputer Science. Questions for discussion Part II. Computer Science COMPUTER SCIENCE. Section 4.2.
COMPUTER SCIENCE S E D G E W I C K / W A Y N E PA R T I I : A L G O R I T H M S, T H E O R Y, A N D M A C H I N E S Computer Science Computer Science An Interdisciplinary Approach Section 4.2 ROBERT SEDGEWICK
More informationIntroduction to Python and its unit testing framework
Introduction to Python and its unit testing framework Instructions These are self evaluation exercises. If you know no python then work through these exercises and it will prepare yourself for the lab.
More informationList reversal: back into the frying pan
List reversal: back into the frying pan Richard Bornat March 20, 2006 Abstract More than thirty years ago Rod Burstall showed how to do a proof of a neat little program, shown in a modern notation in figure
More informationData Structures and Algorithms Winter Semester
Page 0 German University in Cairo December 26, 2015 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2015-2016 Final
More informationC++ For Science and Engineering Lecture 17
C++ For Science and Engineering Lecture 17 John Chrispell Tulane University Monday October 4, 2010 Functions and C-Style Strings Three methods for representing the C-style string: An array of char A quoted
More informationTuring Machines Part Two
Turing Machines Part Two Recap from Last Time Our First Turing Machine q acc a start q 0 q 1 a This This is is the the Turing Turing machine s machine s finiteisttiteiconntont. finiteisttiteiconntont.
More informationTuring Machines Part II
Turing Machines Part II Hello Hello Condensed Slide Slide Readers! Readers! This This lecture lecture is is almost almost entirely entirely animations that that show show how how each each Turing Turing
More informationIntroduction to Python
Introduction to Python Luis Pedro Coelho luis@luispedro.org @luispedrocoelho European Molecular Biology Laboratory Lisbon Machine Learning School 2015 Luis Pedro Coelho (@luispedrocoelho) Introduction
More informationOutline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10
Merge Sort 1 / 10 Outline 1 Merging 2 Merge Sort 3 Complexity of Sorting 4 Merge Sort and Other Sorts 2 / 10 Merging Merge sort is based on a simple operation known as merging: combining two ordered arrays
More informationAn Introduction to MAGMA
An Introduction to MAGMA Don Taylor The University of Sydney 13 February 2012 Don Taylor (The University of Sydney) Magma Programming 13 February 2012 1 / 31 A little history MAGMA is a programming language
More informationIntroduction to Python
Introduction to Python Luis Pedro Coelho Institute for Molecular Medicine (Lisbon) Lisbon Machine Learning School II Luis Pedro Coelho (IMM) Introduction to Python Lisbon Machine Learning School II (1
More informationFPGA Resource Utilization Estimates for NI crio LabVIEW FPGA Version: 8.6 NI-RIO Version: 3.0 Date: 8/5/2008
FPGA Resource Utilization Estimates for NI crio-9104 LabVIEW FPGA Version: 8.6 NI-RIO Version: 3.0 Date: 8/5/2008 Note: The numbers presented in this document are estimates. Actual resource usage for your
More informationQuadratic Equations Part I
Quadratic Equations Part I Before proceeding with this section we should note that the topic of solving quadratic equations will be covered in two sections. This is done for the benefit of those viewing
More informationLecture 16 More Profiling: gperftools, systemwide tools: oprofile, perf, DTrace, etc.
Lecture 16 More Profiling: gperftools, systemwide tools: oprofile, perf, DTrace, etc. ECE 459: Programming for Performance March 6, 2014 Part I gperftools 2 / 49 Introduction to gperftools Google Performance
More informationExtensibility Patterns: Extension Access
Design Patterns and Frameworks Dipl.-Medieninf. Christian Piechnick INF 2080 christian.piechnick@tu-dresden.de Exercise Sheet No. 5 Software Technology Group Institute for SMT Department of Computer Science
More informationCS415 Compilers Syntax Analysis Top-down Parsing
CS415 Compilers Syntax Analysis Top-down Parsing These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Announcements Midterm on Thursday, March 13
More information