EPL232: Programming Techniques and Tools

Intermediate & Advanced Programming in C and UNIX

Undergraduate Compulsory Prerequisite: EPL131

Instructor

Photo of Andreas Aristidou

Andreas Aristidou

Office: B113, FST01


Lab Instructor

Photo of Pavlos Antoniou

Pavlos Antoniou

Office: B109, FST01

Course Info

  • Type: Undergraduate (Compulsory)
  • Credits: 7.5 ECTS
  • Prerequisite: EPL131 - Programming Principles I

Lectures

  • Lectures A: Tuesday & Friday, 10:30–12:00 (ΧΩΔ02 #009)
  • Lectures B: Tuesday & Friday, 12:00–13:30 (ΧΩΔ02 #116)
  • Recitations A: Wednesday, 12:00–13:00 (ΧΩΔ02 #007)
  • Recitations B: Wednesday, 13:00–14:00 (ΧΩΔ02 #008)

Labs

  • Laboratory: Monday or Thursday, 09:00–10:30 or 10:30-12:00 or 12:00-13:30 (ΘΕΕ01 #103)

Overview

This course aims to accompany the student in the transition from simple scripting languages to modern system programming, by reviewing basic imperative programming techniques and using them in the ANSI C programming language. To this aim, we first briefly review fundamental programming principles and techniques (such as expressions, declarations, statements and control structures, recursion, etc), and we become familiar with the standard design tools for programs.

We first implement small programs in C in simple areas. We gradually define functions and data structures that are used for writing medium-size programs. In particular, in the first part of the course the student will learn how to write programs in C, using the data types and control structures of C. Then, we discuss the implementation of C programs in the UNIX environment. The student will first learn how to use the UNIX shell and tools and then how to write programs in C that call UNIX system functions. Finally, we consider some basic methods for program development and study the tools that UNIX offers to the programmer for managing relatively big programs (e.g., make files, version control systems, etc.).

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.
Download Syllabus (PDF)

Course Schedule and Lectures

Introduction: Syllabus & Basics C Fundamentals

Course Objectives and Syllabus, C Advantages and Drawbacks, Comparing C with JAVA, First Program, Directives, Functions, Statements, Compiling C Programs with GCC, Native vs. Intermediate Compilation [C/C++/Objective-C vs. JAVA/Android/C#], Basic Data Types, basic comments, x86/x64 data types basics, reserved identifiers.

Fundamentals I: Formatted I/O, Expressions, Selection Statements, Loops Expressions & 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).

Fundamentals II: Basic Types, Arrays and Functions Arrays & 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.

Program Organization Files & Scope

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).

Memory I: Pointers Pointers

Pointer Variables: Declaring and Using, Address (&) and Indirection Operators (*), Pointer Assignment (=), Pointer as Arguments, Using const to protect arguments, Pointers as Return Values.

Memory II: Pointers and Arrays Pointer Arithmetic

Pointer Arithmetic (adding, comparing), Pointer 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.

Memory III: Strings, Array of Pointers and Examples Strings

String Literals and Variables, Reading and Writing, Implementing strcpy(), strlen(), strcat(), strcmp(), Arrays of Strings, Command Line Arguments (argc and *argv[]).

Memory IV: Structures, Unions and Enumerations Structures

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.

Memory V: Dynamic Storage Allocation Dynamic Memory

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.

Program Structures I: Basic Linked-Lists, Pointer-to-Pointer and Stacks / Queues Linked Lists

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.

Writing Large Programs Multi-file 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.

Writing Large Programs and the Preprocessor 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.

Program Structures II: Linked-Lists Data Structures

Ordering of data in Linked-lists (limitations of stacks, queues), Implementing Sorted Linked-list Functions: printList, Recursive functions.

Program Structures III: Additional Linked-Lists Functions and Examples Linked List Operations

Linked-Lists functions (recursive and repetitive implementations): insert, delete, eliminateDuplicates, mergeLists.

Program Structures IV: Doubly-linked Lists 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.

Tools I: Large-scale Software, Modules & Libraries, Testing Software Engineering

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).

Tools II: Team Development, SVN and Open Source Software Development Version Control

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.

Selected Topic I: Low-level Programming I Bitwise Operations

Bitwise Operators, Using Bitwise operators to access bits and basic operations (setting a bit, clearing a bit, and testing a bit), names in masks.

Selected Topic II: Low-level Programming II Low-level Programming

XOR encryption example, Bit fields in structures, how bit fields are stored with and without memory alignment issues, complete previous lectures.

Basic Unix System Commands UNIX Basics

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.

Unix Commands and System Utilities I UNIX Tools

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.

Unix Commands and System Utilities II UNIX Process Management

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).

Lab Sessions & Materials

Please read the following information carefully!


The laboratory sessions of this course will use Visual Studio Code (VS Code) as the integrated development environment (IDE), GCC or MinGW as the C compiler, and Git/GitHub for version control and assignment management. Students are expected to get familiar with these tools throughout the semester.
STEP 1: Install VSCode + GCC/MinGW + Git: Before attending the first lab, please follow the provided development tools guide (especially sections 1, 3 and 5) to install VS Code, GCC or MinGW, and Git on your computer.
STEP 2: Set up your GitHub account and access Assignment in Classroom50: Please read the following guide Access Assignments Using GitHub, which includes step-by-step instructions and screenshots for:
  • creating a GitHub account
  • joining Classroom50 for assignment management
  • accepting Assignment (when posted)
  • cloning Assignment repository in VS Code

GitHub will be used to track your development progress, securely store your code online, work on different features while maintaining previous versions, collaborate and share your work with others, and allow instructors to monitor your progress and contributions to team assignments.

Also read this guide on Git best practices for software development and version control that will be used during the course.

Week Topic Material
1 C Program Structure and Fundamentals (in/out, operators, conditionals, loops) Lab Files
2 Arrays, functions, file manipulation Lab Files
3 Pointers — Doxygen documentation Lab Files
4 The string.h library Lab Files
5 Quiz 1
6 Dynamic allocation, structs, enums and unions Lab Files
7 Stacks and Queues Lab Files
8 Macros, Multiple file organization, makefiles and linked list operations Lab Files
9 Binary tree operations Lab Files
10 Quiz 2
11 Binary files, hexdump and low-level programming Lab Files
12 Unix Commands I Lab Files
13 Unix Commands II Lab Files

Assignments

To be announced.

Text Book and Bibliography