Reading order of The Witcher

Posted by Michał ‘mina86’ Nazarewicz on 31st of July 2022

Without beating around the bush, the reading order for the Witcher books is as follows:

1.The Last WishShort
2.Sword of Destiny
3.Blood of ElvesThe Witcher Saga
4.Time of Contempt
5.Baptism of Fire
6.The Tower of the Swallow
7.The Lady of the Lake
8.Season of Storms

Curious case of missing π

Posted by Michał ‘mina86’ Nazarewicz on 28th of June 2022

π is one of those a constant which pops up when least expected. At the same time it’s sometimes missing when most needed. For example, consider the following application calculating area of a disk (not to be confused with area of a circle which is zero):

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
	for (int i = 1; i < argc; ++i) {
		const double r = atof(argv[i]);
		printf("%f\n", M_PI * r * r);

It uses features introduced in the 1999 edition of the C standard (often referred to as C99) so it might be good to inform the compiler of that fact with a -std=c99 flag. Unfortunately, doing so leads to an error:

$ gcc -std=c99 -o area area.c
area.c: In function ‘main’:
area.c:8:18: error: ‘M_PI’ undeclared (first use in this function)
    8 |   printf("%f\n", M_PI * r * r);
      |                  ^~~~

What’s going on? Shouldn’t math.h provide the definition of M_PI symbol? It’s what the specification claims after all. ‘glibc is broken’ some may even proclaim. In this article I’ll explain why the compiler conspire with the standard library to behave this way and why it’s the only valid thing it can do.

Pro tip: You can put URLs in C & C++ code

Posted by Michał ‘mina86’ Nazarewicz on 1st of April 2022

Documenting source code is important part of software engineering. Code is read more often than it’s written making it crucial to provide enough context for reader to understand what the implementation is doing. This can come in the form of links to external resources providing description of an algorithm, reference for an API or historic context justifying the code.

As it turns out, C and C++ languages offer a little-known feature which allows URLs to be included directly in the function source code. For example:

static float rsqrt(float x) {
	auto i = std::bit_cast<uint32_t>(x) >> 1;
	auto y = std::bit_cast<float>(UINT32_C(0x5F375A86) - i);
	y *= 1.5f - x * 0.5F * y * y;
	return y;