On this page
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
- C23 compile-time type operator: Evaluates the type of an expression without evaluating it—great for type-safe
MAX(a, b)macros that evaluate each argument only once.
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
- tuts/c/builtins/__func__ Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Generic Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/compilation_and_internals/preprocessor_and_macros Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Alignof shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Atomic shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Noreturn shared tags: #builtins, #c, #prog, #tier