Instructor: Andreas Aristidou
Type: Undergraduate (Compulsory)
Lectures A: Tuesday & Friday, 10:30-12:00 (ΧΩΔ02 #B205)
Recitations A: Wednesday, 11:00-12:00 (ΧΩΔ02 #B205)
This lecture has been structured based on the notes of the Associate Professor Demetris Zeinalipour.
Overview
The course teaches intermediate and advanced programming concepts, techniques and tools through a language that compiles to machine code. The course familiarizes the students with advanced programming
constructs utilized for handling memory and files. Advanced topics in compilation, debugging, documentation and optimization of software. Methodological aspects in developing large-scale system software
that addresses complex problems. Basic commands for programmers in the UNIX operating system.
News
Sign-up now to Moodle using code handed out in class!
Content
- Introduction to C for Programmers: types x86/x64, loops, selections, expressions, arrays, functions, IO, basic program organization,
- Advanced C programming constructs: program anatomy and processes, memory and addresses (pointers, pointers and arrays, strings and examples), structures, unions and enumerations. Linear and non-linear programming data structures (dynamic memory allocation, lists, queues, doubly-linked lists, trees, applications and examples).
- Advanced Compilation Topics and Tools: preprocessor directives, compiling multiple files with makefiles, static (.a) and dynamic (.so) linking of object files (.o), error handling (assert.h), static and dynamic code analysis (valgrind and gprof).
- low-level programming (binary operators and examples, binary files and hexdump).
- Basic commands for programmers in the UNIX operating system: file system, redirection and pipes, permissions and basic filters.
You can download the syllabus of the course here...
Course Schedule and Lectures
- Introduction: Syllabus & Basics Course Objectives and Syllabus, C Advantages and Drawbacks, Comparing C with JAVA, First Program, Directives,
Functions, Statements, Compiling C Programs with GCC, Native vs. Intermed. Compile [C/C++/Objective-C vs. JAVA/Android/C#], Basic Data Types, basic comments, x86/x64 data types basics,
reserved identifiers. [PDF | 3.98 MB]
- Fundamentals I: Formatted I/O, Expressions, Selection Statements, Loops The printf() and scanf() functions,
Arithmetic Operators, Assignment Operators lvalues), Incr/Decr Operators, Expression Evaluation (precedence and order), Logical Expressions and _BOOL (C99), if..else, dangling-else, switch ... break,
Loops (while, do, for, break, continue, goto). [PDF | 0.63 MB]
- Fundamentals II: Basic Types, Arrays and Functions Integer, Float, Character Types on x86 and x64 platforms, Type overflow
and explanation, Type Conversion (Implicit and Casting), Type Definitions with typedef, The sizeof operator, 1-d arrays and m-d arrays: subscripting, initialization, sizeof.
[PDF | 2.21 MB]
Recitations I [PDF | 0.28 MB]
- Program Organization Local Variables (auto vs. static), External Variables, Blocks {}, Scope, Organizing a C Program,
Comments with Documentation Systems (doxygen), Files: fopen, fread, fwrite, examples with srand(), rand() and time(NULL). [PDF | 1.12 MB]
- Memory I: Pointers Pointer Variables: Declaring and Using, Address (&) and Indirection Operators (*), Pointer Assignment (=), Pointer as Arguments,
Using Const to protect arguments, Pointers as Return Values. [PDF | 1.01 MB]
Recitations II [PDF | 0.29 MB]
- Memory II: Pointers and Arrays Pointer Arithmetic (adding, comparing), Pointers Variables and types,
Using Pointers for Array Processing, Combining increment (++) and indirect (*) operators, arrays-functions-pointers, pointers and multi-dimensional arrays ((*p)[i]): working with rows,
working with columns, sum example in five different ways. [PDF | 1.18 MB]
- Memory III: Strings, Array of Pointers and Examples String Literals and Variables, Reading and Writing, Implementing strcpy(), strlen(), strcat(), strcmp(), Arrays of Strings,
Command Line Arguments (argc and *argv[]). [PDF | 1.16 MB]
Recitations III (Corrected!!!) [PDF | 0.18 MB]
- Memory IV: Structures, Unions and Enumerations Structures: Representation, Initialization, Types, Nested Structures
and Arrays, Examples, Pointer-to-Structures (*p).field | p->field), Memory Alignment Issues (__attribute__ ((__packed__))); Unions: Representation, Initialization, Examples and Applications; Enumerations:
Representation, Examples and Applications. [PDF | 1.27 MB]
- Memory V: Dynamic Storage Allocation Dynamic Storage Allocation Functions, NULL, Dynamically Allocation Functions: malloc, calloc and realloc,
Examples with Strcat, Deallocating Storage: free function, Dangling Pointer Problem, Pitfalls and Examples. [PDF | 0.72 MB]
- Program Structures I: Basic Linked-Lists, Pointer-to-Pointer and Stacks / Queues Data structures: introduction and examples,
self-referential structures, constructing a basic linked-list, pointer-to-pointer (void **a) and dynamic multi-dimensional matrices, Stack: Basics and Definitions, Implementing a stack with dynamic memory
allocation, Queue: Basics and definitions, Implementing a queue with dynamic memory allocation. [PDF | 0.52 MB]
Recitations IV [PDF | 0.25 MB]
- Writing Large Programs Source Files: Reverse Polish Notation (RPN) Problem and Solution with Stack in 1 file,
Organizing a Program in Multiple Files (RPN with 3 .c files), Compiling Multiple Files with GCC, Header Files: RPN problem with def.h, Pre-processor Directive: #include, Variables in Multiple
Files and extern. [PDF | 0.46 MB]
- Writing Large Programs and the Preprocessor Nested Includes and Hierarchies, Protecting Header files with #ifndef..#endif,
9 Steps for Breaking a Program into Multiple Files, Examples (justify and RPN), Automating Compilation with Makefiles, A Generic Makefile and eClipse Makefiles, Preprocessor Directives: #include and #define
in further detail, usage examples, parameterized macros: examples, advantages and disadvantages. [PDF | 0.78 MB]
- Program Structures II: Linked-Lists Ordering of data in Linked-lists (limitations of stacks, queues),
Implementing Sorted Linked-list Functions: printList, Recursive functions.
[PDF | 1.42 MB]
- Program Structures III: Additional Linked-Lists Functions and Examples Linked-Lists functions (recursive and repetitive implementations): insert, delete,
eliminateDuplicates, mergeLists
[PDF | 1.40 MB]
- Program Structures IV: Doubly-linked Lists Doubly-linked lists: Declarations and Definitions, Implementing put(l,x,y) recursively and repetitively, Doubly-Sorted Linked-lists:
implementing printlist(l), insert(l,x) and delete(l,x), Circular linked list.
[PDF | 1.34 MB]
Recitations V [PDF | 1.13 MB]
- Tools I: Large-scale Software, Modules & Libaries, Testing Large-scale software and problems (source-lines-of-code SLOC and
real examples), Modules and Libraries: Information Hiding and Abstract Data Types, Design Issues for Abstract Data Types, Cohesion and Coupling, Module Types: data pool, libraries static (.a) and dynamic
(.so, .dll), abstract objects, abstract data types. Testing: Drivers, assert.h and Assertions, Unit Testing with tools: CUnit (for C) and JUnit (for JAVA), Dynamic Program Analysis
(program performance): Static vs. Dynamic program analysis, Profiling Tools: Valgrind, gprof (for C) and JProfiler (for JAVA).
[PDF | 2.20 MB]
- Tools II: Team Development, SVN and Open Source Software Development Software Versioning and
Revision Control Systems: Tools (open and proprietary), SVN Architecture, Connecting to our SVN through eClipse, UNIX, operating system and web browser, SVN strategies:
lock/modify/unlock, copy/modify/merge, Open-Source Software (OSS): examples and incentives, Free OSS, Licences for Free OSS (MIT, BSD, GPL and LGPL), Use cases: bestzip,
cyimg, linux, Source code Preamble for MIT, GPL and FreeBSD licences.
[PDF | 3.30 MB]
- Selected Topic I: Low-level Programming I Bitwise Operators, Using Bitwise operators to access bits and basic operations
(setting a bit, clearing a bit, and testing a bit), names in masks.
[PDF | 1.65 MB]
- Selected Topic II: Low-level Programming II XOR encryption example, Bit fields in structures, how bit fields are stored
with and without memory alignment issues, complete previous lectures.
[PDF | 1.28 MB]
Recitations VI [PDF | 0.39 MB]
- Basic Unix System Commands: Directory/File handling (mkdir, rmdir, cp, mv, rm), File Display and Conversion (file, head,
tail, cat, more, wc, sort, uniq, iconv), In/Out Streams (stdin, stdout, stderr), File Redirection, Piping.
[PDF | 1.71 MB]
- Unix Commands and System Utilities I: UNIX commands (echo, touch), Ownership and Access Rights(chmod, chgrp, chown, umask, suid, sgid,
sticky bit), Regular Expressions in BRE and ERE (grep, egrep), Usage and Examples.
[PDF | 2.53 MB]
- Unix Commands and System Utilities II: Process Control (jobs, ps, fg, bg, kill, top), Find File and Program (which, whereis, find,
exec, xargs), UNIX Commands (alias, cut, tr, tee, mail, comm, diff, crontab).
[PDF | 2.01 MB]
Lab Schedule
- Tools Moodle, Cygwin, Eclipse CDT, GCC Basics
Exercises Basic Programs & Fundamentals (operators, conditionals) [ZIP | 0.32 MB]
- Tools Google style guide (naming, formatting, comments), Using Doxygen to generate javadoc style comments for C programs
Exercises Fundamentals (files, loops, functions) through examples with string.h [ZIP | 1.84 MB]
- Exercises Fundamentals (tables, pointers) with emphasis on pointers [ZIP | 0.09 MB]
- Exercises Re-implement string.h library using pointers (string length, string copy, string concat, substring, string compare) [ZIP | 0.15 MB]
- Exercises Dynamic allocation, structs, enum, union (implementing a shape, a sparse matrix data structures, small database) [ZIP | 0.13 MB]
- Exercises Stacks and Queues to solve different problems (Josephus problem, Balancing parentheses) [ZIP | 0.13 MB]
- Exercises Multiple file organization, makefile (infix to postfix expression, Balancing parentheses) [ZIP | 0.09 MB]
- Exercises Macros, conditional compilation, pre-processor directives & Linked lists operations: length(), print(), next(), previous(), retrieve(), locate(), insert(), delete() [ZIP | 0.95 MB]
- Tools Dynamic code analysis: Valgrind, gprof [ZIP | 282 KB]
- Exercises Binary files, hexdump command, binary files and linked lists, __attribute__((packet)). Low-level programming: Bit twiddling hacks [ZIP | 0.7 MB]
- Exercises Unix commands [ZIP | 81 KB]
Assignments
All Assignments will be announced in Moodle. Sign-up using the code handed out in class!
Text Book and Bibliography
- C Programming: A Modern Approach, K.N. King, Second Edition, ISBN-10: 0393979504, ISBN-13: 978-0393979503, 832 pages, W. W. Norton & Company, 2008.
- Your UNIX/Linux: The Ultimate Guide, 3rd Edition, Sumitabha Das, McGraw Hill, ISBN-13 9780073376202, 800 page, 2013.
- Computer Systems: A Programmer's Perspective, 3rd Edition Bryant and O'Hallaron, Pearson Global Edition, ISBN-13 978-292-10176-7, 2016.
Links and Manuals
To be uploaded soon...