//препроцессор выбирает код до компиляции:
//другая ветвь вообще не компилируется
#define DEBUG 1
#define VERSION 3
#if DEBUG
const char *mode = "debug";
#else
const char *mode = "release";
#endif
//mode is "debug"
//#if вычисляет целочисленные выражения, #elif - его "else if"
#if VERSION >= 3
int features = 30;
#elif VERSION == 2
int features = 20;
#else
int features = 10;
#endif
//features is 30
//#error останавливает сборку с сообщением,
//здесь только когда условие истинно
#if VERSION < 2
#error "VERSION 2 or newer is needed"
#endif
//#ifdef и #ifndef лишь спрашивают, определено ли имя;
//defined() делает то же внутри #if,
//C23 добавляет #elifdef и #elifndef
#ifdef LOGGING
bool logging = true;
#else
bool logging = false;
#endif
//logging is false
//компилятор определяет собственные имена: так код
//выбирает платформу (песочница работает на Linux)
#if defined(_WIN32)
const char *platform = "Windows";
#elif defined(__APPLE__)
const char *platform = "macOS";
#elif defined(__linux__)
const char *platform = "Linux";
#else
const char *platform = "unknown";
#endif
//platform is "Linux"
//#if 0 отключает кусок кода, даже с комментариями внутри
#if 0
printf("this line is not compiled\n"); /* даже не виден */
#endif
printf("mode is %s\n", mode);
printf("features is %d\n", features);
printf("logging is %s\n", logging ? "true" : "false");
printf("platform is %s\n", platform);