Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:ClickHouse ClickHouse Defines

From Leeroopedia


Knowledge Sources
Domains Build_System, Portability
Last Updated 2026-02-08 00:00 GMT

Overview

Core compiler macros and definitions used throughout ClickHouse for portability and optimization.

Description

Defines platform checks, compiler hints (likely/unlikely), inlining directives, assertion macros (chassert), and Thread Safety Analysis annotations.

Usage

Use for writing portable code, adding compiler hints, implementing assertions, or annotating code for TSA.

Code Reference

Source Location

Signature

// Branch prediction hints
#define likely(x)   (__builtin_expect(!!(x), 1))
#define unlikely(x) (__builtin_expect(!!(x), 0))

// Inlining control
#define ALWAYS_INLINE __attribute__((__always_inline__))
#define NO_INLINE __attribute__((__noinline__))

// Assertions
#define chassert(x) /* ... */
#define UNREACHABLE() /* ... */

// Thread Safety Analysis
#define TSA_GUARDED_BY(...)
#define TSA_REQUIRES(...)
#define TSA_NO_THREAD_SAFETY_ANALYSIS

Import

#include <base/defines.h>

Usage Examples

#include <base/defines.h>

// Branch hints
if (likely(common_case)) {
    // Compiler optimizes for this path
}

if (unlikely(error_condition)) {
    // Rare path
}

// Force inlining
ALWAYS_INLINE void hot_function() { }

// Assertions
chassert(ptr != nullptr);
chassert(size > 0, "Size must be positive");

// Thread safety annotations
int counter TSA_GUARDED_BY(mutex);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment