Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

C language-version and feature-availability macros

Distinguish the language version, execution environment, missing optional features, and header revisions. These macros select code during compilation; they do not attest that the production runtime works.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
/* C23 or later */
#endif

#ifndef __STDC_NO_ATOMICS__
/* Atomic support is not declared absent. */
#endif

#include <limits.h>
#if defined(__STDC_VERSION_LIMITS_H__) && __STDC_VERSION_LIMITS_H__ >= 202311L
/* C23 header revision or later */
#endif

__STDC__ is 1 in a conforming implementation; __STDC_VERSION__ is 202311L for C23. __STDC_HOSTED__ is 1 for hosted and 0 for freestanding environments.

Macros valued 1 indicate missing support: __STDC_NO_ATOMICS__ — atomic types and <stdatomic.h>; __STDC_NO_COMPLEX__ — complex types and <complex.h>; __STDC_NO_THREADS__ — <threads.h>. In C23, __STDC_NO_VLA__ concerns only automatic-storage VLAs, not all variably modified types; VLA parameter declarations remain required.

After including the corresponding headers, check their revisions: __STDC_VERSION_STDIO_H__ → <stdio.h>, __STDC_VERSION_STDLIB_H__ → <stdlib.h>, __STDC_VERSION_LIMITS_H__ → <limits.h>, __STDC_VERSION_STDINT_H__ → <stdint.h>, __STDC_VERSION_STDBIT_H__ → <stdbit.h>, __STDC_VERSION_STDCKDINT_H__ → <stdckdint.h>. All have value 202311L in C23.

Use defined and >= comparisons, not version equality. Do not define these names yourself. A repository C23 flag does not attest library conformance or the production runtime.

Examples

#include <limits.h>
#include <stdio.h>

int main(void)
{
    printf("c23=%d\n", __STDC_VERSION__ >= 202311L);
#ifdef __STDC_VERSION_LIMITS_H__
    printf("limits_revision=%ld\n", (long)__STDC_VERSION_LIMITS_H__);
#else
    puts("limits_revision=not-reported");
#endif
    return 0;
}

Result

c23=1
limits_revision=not-reported

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources