C pensum

A free resource for C programming is “C Notes for Professionals book”. It can be found at https://books.goalkicker.com/CBook/ . The book is published under Creative Commons BY-SA.

Tools directly related to the C-programming we will do: gcc, valgrind, gdb, make, man

We do not have a definite curriculum for C-programming in this course. To make it easier for you to know what you are expected to learn we have compiled a summary of the most important parts of the different topics we will encounter.

Memory

Goal: You should be able to manage memory in a good way. You should be able to answer the questions below.

How is a running program laid out in memory?

Stack memory and heap memory. When is stack memory used? When is heap memory used? How do they differ in terms of management and scope? How are variables stored and represented in memory? What is dynamic allocation?

 

Where are global variables located? Where is the code?

How are structs, arrays and other variables laid out in memory? What value does a variable start with when it is declared?

 

How do you address a bit?

Why are memory leaks undesirable? How do you detect a memory leak?
A bit harder: How can you identify a memory leak through observing performance?

 

Basic data types

Goal: You should know what the different data types are, how they differ and their limitations. You should be able to modify data at bit-level.

Whole integer types: short, int, long, long long
All these types can be unsigned or signed. The default is that it is signed. What is the difference between signed and unsigned? What happens if an unsigned variable is set to a value less than 0?
How many bytes are the data types (typically)?
Important to pick the correct data type, especially when we come to pointers.

Floating point: float, double
What are the differences?

Bit manipulation. How can one set and unset a specific bit in a byte? Why is this even useful?

 

Other data types

Goal: You should be able to use these data types.

Array. How is a static array declared? Can the size of an array be changed? Where is the size of an array stored, if anywhere?

Struct. Why do we have this data type?



 

Pointers

Goal: Understand the properties and power of using pointers, also in combination with typecasts.

 

  • What is a pointer?

  • What kinds of things can a pointer point to?

    • What is a pointer to a function?

    • What is a pointer to a pointer? (or triple-/quadruple-pointer)

  • How do you create a pointer?

  • How do you access data pointed to by a pointer? (this is called de-referencing)

  • How does the type of the pointer affect how memory is interpreted?

  • How do pointers and arrays differ, and how are they similar?

 

Pointers are types that have two properties: the type they can point to, and the indicator that this is a pointer (the * symbol).

Data structures

Goal: You should be able to implement different data structures that relies on pointers. The focus is on being able to use pointers well. You should avoid memory leaks when elements are deleted and always initialize pointers.

Intrusive and non-intrusive linked list. What is the difference?

How do you implement trees and graphs in C?

 

Functions

Goal: Use functions correctly to structure programs in an understandable manner. Understand how and what they change (allocate stack memory, change stack pointer, …) and what they do not change (heap memory, …)

 

C knows only call-by-value. How can you change a variable owned by the caller without copying it? (unlike Java objects)

 

Can you and should you return complex data structures from a function?

 

Can you and should you return pointers to local variables (variables on a function’s stack)?

 

Interacting with the filesystem

Goal: You should be able to read from and write to files. You should understand what a file is and what it contains.

What is the difference between buffered and unbuffered file operations?

What is a file, what can it contain?

 

Socket programming

Goal: You should be able to create and connect to sockets. You should be able to send messages between two sockets. You should know the similarities and differences between TCP and UDP, and how these might affect application layer protocol implementation.

What does it mean that TCP is stream-oriented, and what requirements does this impose on users of TCP?

A great resource for socket programming is Beej's Guide to Network Programming.


 

From code to executable 

Goal: You should be able to explain how source files are compiled and linked to one single executable.
 

Why are there header files (.h) and code files (.c)? What do you put into each of them?

 

Why should you not #include .c files?

 

Why should you not put code into .h files and what happens when you do it?

 

How do you develop modular code? There are no classes in C, which parts should you combine into a file?


How are files containing code compiled into an executable file? How does this file look, and how does the operating system execute it? Hint: readelf


 

Publisert 15. jan. 2020 14:07 - Sist endret 15. jan. 2020 14:10