Category Archives: C Programming

Chapter 63: Common pitfalls

This section discusses some of the common mistakes that a C programmer should be aware of and should avoid making. For more on…
Continue reading

Chapter 62: Common C programming idioms and developer practices

Section 62.1: Comparing literal and variable Suppose you are comparing value with some variable if ( i    == 2) //Bad-way { doSomething; }…
Continue reading

Chapter 61: Valgrind

Section 61.1: Bytes lost -- Forgetting to free Here is a program that calls malloc but not free: #include <stdio.h> #include <stdlib.h> int…
Continue reading

Chapter 60: Testing frameworks

Many developers use unit tests to check that their software works as expected. Unit tests check small units of larger pieces of software,…
Continue reading

Chapter 59: Interprocess Communication (IPC)

Inter-process communication (IPC) mechanisms allow different independent processes to communicate with each other. Standard C does not provide any IPC mechanisms. Therefore, all…
Continue reading

Chapter 58: Multithreading

In C11 there is a standard thread library, <threads.h>, but no known compiler that yet implements it. Thus, to use multithreading in C…
Continue reading

Chapter 57: Threads (native)

Section 57.1: Inititialization by one thread In most cases all data that is accessed by several threads should be initialized before the threads…
Continue reading

Chapter 56: Unions

Section 56.1: Using unions to reinterpret values Some C implementations permit code to write to one member of a union type then read…
Continue reading

Chapter 55: Inlining

Section 55.1: Inlining functions used in more than one source file For small functions that get called often, the overhead associated with the…
Continue reading

Chapter 54: Constraints

Section 54.1: Duplicate variable names in the same scope An example of a constraint as expressed in the C standard is having two…
Continue reading