On this page
  1. typeof
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

typeof

Prev: _Generic | Up: builtins | Next: __func__
Rel: Preprocessor & Macros
Ref: cppreference — typeof
Tags: #public #prog #c #builtins #tier/standard


Availability

Built-in (Operator (C23)) — requires no #include header.

Syntax & Overview

typeof(expr)  |  typeof_unqual(expr)

Yields the type of an expression at compile time (typeof_unqual strips const/volatile/_Atomic).

Notes & Pitfalls

Example

#include <assert.h>

#define MAX_VAL(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; })
int main(void) { assert(MAX_VAL(3, 7) == 7); }

Linked from

Related notes