Skip to content
Tutorials Center
My learning

Topics

Lesson 98 of 135 ยท Advanced C

Modern C: C99 to C23

Tour modern C from C99 to C23 - the headline features of each standard with runnable examples, how to check __STDC_VERSION__, and what today's compilers support.

C is over fifty years old, but it hasn't stood still. The language has been revised by an ISO committee several times, and each revision added features that make code safer, clearer or more portable. Much of the C you'll find in old books and university slides is C89: all variables declared at the top of a block, no // comments, no bool, no fixed-width integers. Modern C looks noticeably different, and the newest standard, C23, adds keywords like nullptr, constexpr, typeof and auto.

This lesson is a guided tour of the standards, from C99 to C23. For each one you'll see the features that matter most in everyday code, with runnable examples (our editor compiles with -std=c23), plus the support situation in GCC, Clang and Microsoft's compiler. Many of these features have their own lessons; this page shows how they fit together historically and links to the details.

The timeline

Standard Year __STDC_VERSION__ In one sentence
K&R C 1978 (none) The language described in Kernighan and Ritchie's book, before standardization
C89 / C90 1989 / 1990 (none) The first ANSI/ISO standard: prototypes, void, const, the standard library
C95 1995 199409L A small amendment: wide-character functions, digraphs
C99 1999 199901L The big modernization: //, declarations anywhere, bool, stdint.h, designated initializers
C11 2011 201112L Threads, atomics, _Generic, _Static_assert, alignment; gets removed
C17 (C18) 2018 201710L Bug fixes and clarifications only, no new features
C23 2024 202311L bool/nullptr/constexpr/typeof keywords, attributes, #embed, checked arithmetic

C23 was finished in 2023 and officially published by ISO in October 2024; the committee is already working on the next revision, informally called C2y. "C18" and "C17" are the same standard (the work finished in 2017, ISO published it in 2018).

Which standard am I compiling?

The predefined macro __STDC_VERSION__ holds the standard your compiler is using, as a long in the form yyyymm. You can test it with #if to enable newer features only when they're available, as covered in Conditional Compilation.

C Which C standard is this?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

C11 made some features optional and gave each one a macro an implementation defines when it doesn't support it: __STDC_NO_THREADS__, __STDC_NO_ATOMICS__, __STDC_NO_VLA__ and __STDC_NO_COMPLEX__. The test is inverted ("no" macro absent means supported), which surprises everyone the first time.

To choose a standard yourself, pass -std=c99, -std=c11, -std=c17 or -std=c23 to GCC or Clang. The gnu variants (-std=gnu17, -std=gnu23) add GCC extensions on top; GCC 15 uses gnu23 by default, while GCC 11 to 14 default to gnu17. With Microsoft's compiler you use /std:c11, /std:c17 or /std:clatest.

C99: the modernization

C99 changed day-to-day C more than any other revision. If you learned C from a modern course (including this one), you've been writing C99 all along:

  • // comments (see Comments).
  • Declarations anywhere in a block, including in for loops: for (int i = 0; ...). C89 required all declarations at the top of a block.
  • <stdbool.h> (bool, true, false) on top of the new _Bool type (Booleans).
  • <stdint.h> and <inttypes.h>: int32_t, uint8_t, int64_t, PRId64 and friends (Integer Types). Also long long, guaranteed to be at least 64 bits.
  • Designated initializers (.x = 1, [3] = 7) and compound literals ((struct point){1, 2}) (Structures).
  • Variable-length arrays (int grid[rows][cols]; with run-time sizes), made optional again in C11 (Multidimensional Arrays).
  • inline functions and the restrict pointer qualifier (inline Functions, Pointers and Functions).
  • snprintf, the bounded sprintf you should always prefer.
  • Variadic macros (__VA_ARGS__), __func__, hexadecimal floating-point literals (0x1.8p3), and flexible array members (int data[]; as the last struct member).
C A tour of C99 features

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

snprintf never writes more than the size you give it (here sizeof label), always adds the terminating '\0', and returns the length the full text needed, so a result of sizeof label or more tells you the text was truncated. That one function has prevented countless buffer overflows; see Safe String Handling.

C11: concurrency and generic code

C11 added the features needed for multi-core programs and a few long-requested tools:

  • Threads and atomics: <threads.h>, <stdatomic.h>, _Thread_local and a proper memory model, so data races finally have a definition (Multithreading).
  • _Generic: choose an expression based on the type of an argument, which makes type-generic macros possible (Macros).
  • _Static_assert: a compile-time check, with static_assert as a convenience macro in <assert.h> (Predefined Macros and assert).
  • Alignment control: _Alignas, _Alignof, aligned_alloc (Padding and Alignment).
  • _Noreturn for functions like exit that never return.
  • Anonymous structs and unions inside other structs (Unions).
  • Unicode: char16_t, char32_t, u8"...", u"..." and U"..." string literals.
  • gets removed from the library entirely, after decades of buffer overflows.
  • fopen exclusive mode "wx": fail if the file already exists (File Handling).

The odd-looking names with a leading underscore and capital letter (_Generic, _Bool) were a deliberate choice: such identifiers were already reserved, so adding them couldn't break existing programs. Headers like <stdbool.h> and <stdalign.h> then supplied friendly lowercase macros.

C C11: _Generic, static_assert and anonymous unions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

TYPE_NAME('x') gives int, a nice reminder that character constants have type int in C (in C++ they're char). Also notice that name matched char *: an array argument to _Generic decays to a pointer, as you learned in Pointers and Arrays.

Note: C11 also introduced Annex K, the "bounds-checking interfaces" (strcpy_s, printf_s, ...). It's optional, glibc and most other libraries never implemented it, and Microsoft's versions differ from the standard. Don't count on it in portable code.

C17: a maintenance release

C17 added no features. It fixed defects in the C11 wording, mainly in the threading and atomics specification. If a project says it needs C17, C11 features are what it uses. Many projects still treat C11/C17 as their baseline because every major compiler supports it fully.

C23: the biggest update since C99

C23 brings C closer to C++ in several places and removes some of the language's oldest baggage. The headline features:

  • bool, true, false are now keywords; no header needed (Booleans).
  • nullptr and its type nullptr_t: a null pointer constant that can't be confused with the integer 0 (Pointers).
  • constexpr objects: true compile-time constants with a type (Constants).
  • typeof and typeof_unqual: the type of an expression, standardizing a long-standing GCC extension (void Pointers and Generic Code).
  • auto type inference for object definitions (auto n = 10; makes an int).
  • Attributes: [[nodiscard]], [[maybe_unused]], [[deprecated]], [[fallthrough]], [[noreturn]], [[unsequenced]], [[reproducible]] (switch).
  • static_assert and alignas/alignof/thread_local are keywords, and static_assert no longer needs a message.
  • Digit separators 1'000'000 and binary literals 0b1010 (Integer Types).
  • Empty initializer = {} zero-initializes anything, including VLAs.
  • Enums with a fixed underlying type: enum color : unsigned char { ... } (Enumerations).
  • _BitInt(N): integers of an exact number of bits.
  • Checked arithmetic in <stdckdint.h>: ckd_add, ckd_sub, ckd_mul (Undefined Behavior).
  • Preprocessor: #embed for including binary files, #elifdef/#elifndef, __has_include, #warning.
  • Library: <stdbit.h> (bit counting and rotations), strdup/strndup, memccpy, memset_explicit (a memset the optimizer can't remove), unreachable().
  • Clean-ups: () in a function declaration now means "no parameters", exactly like (void); old K&R-style function definitions are gone; and integers are required to use two's complement.
C C23 in one program

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

A few notes on the details:

  • constexpr in C is deliberately simpler than in C++: it applies only to objects, not functions, and the initializer must be a constant expression. Use it instead of #define for typed constants.
  • auto in C23 is just type inference for a variable you initialize. It's handy with typeof-heavy macros, but spelling out simple types usually reads better.
  • [[nodiscard]] makes the compiler warn when a caller ignores the return value: perfect for functions that return error codes. Add a line twice(1); to main and run again to see the warning. [[deprecated("use twice() instead")]] on a function works similarly: every use of it produces a warning with your message.

Library support lags behind

The compiler implements the language features, but library functions come from the C library on the system (glibc on most Linux machines, the Universal CRT on Windows). C23's library additions only appear once that library is updated. In our editor, for example, <stdbit.h> isn't available yet, and strdup needs #define _POSIX_C_SOURCE 200809L before the includes because the installed glibc predates C23 (it has offered strdup as a POSIX function for decades). On newer systems <stdbit.h> works like this:

C
#include <stdbit.h>   /* C23: needs glibc 2.39+ or another recent C library */

unsigned ones = stdc_count_ones(0xF0u);        /* 4 */
unsigned width = stdc_bit_width(37u);          /* 6: 37 needs 6 bits */
bool power_of_two = stdc_has_single_bit(64u);  /* true */

C23's #embed reads a file's bytes into an initializer at compile time, replacing the old trick of converting files to C arrays with a script:

C
static const unsigned char logo_png[] = {
#embed "logo.png"
};

What compilers support today

Compiler C99 / C11 / C17 C23
GCC Complete Nearly complete in GCC 14 and 15 (-std=c23); GCC 15 defaults to gnu23
Clang Complete Most features in Clang 18+ (-std=c23); #embed since Clang 19
MSVC (Visual Studio) C11 and C17 since VS 2019 16.8 (/std:c11, /std:c17); no VLAs Partial, growing, with /std:clatest

For a new project, a sensible choice is C17 as the baseline, which every compiler handles, adding C23 features where your compilers support them, guarded with __STDC_VERSION__ checks if the code must also build on older toolchains. For embedded targets, check your vendor compiler's documentation: some still only support C99.

Old habits to drop

Modern C makes several classic patterns unnecessary. When you read old code, recognize them; when you write new code, use the replacement:

Old habit Modern replacement
Declare every variable at the top of the function Declare it where it's first used, ideally initialized
#define TRUE 1 / typedef int BOOL bool, true, false
int f() meaning "unknown parameters" int f(void) (and in C23, () means the same)
unsigned long for "a 32-bit value" uint32_t from <stdint.h>
#define MAX 100 for typed constants enum { MAX = 100 }; or C23 constexpr int max = 100;
sprintf, gets, strcpy into fixed buffers snprintf, fgets, length-checked copies
NULL defined as 0 and compared with integers NULL or C23 nullptr, compared only with pointers
Manual overflow checks ckd_add, ckd_mul (C23)

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does printf("%ld\n", __STDC_VERSION__); print when compiling with -std=c11?

    STDC_VERSION uses the year and month of the standard. C11 is 201112L, C99 is 199901L, C17 is 201710L and C23 is 202311L.
  2. 2. Which feature first appeared in C99?

    Designated initializers, compound literals, // comments and <stdint.h> all came with C99. _Generic and threads are C11, nullptr is C23.
  3. 3. In C23, what does int f(); declare?

    C23 removed old-style declarations, so empty parentheses now mean no parameters. Before C23 they meant "parameters not specified".
  4. 4. An implementation defines __STDC_NO_VLA__. What does that tell you?

    The C11 feature-test macros announce missing optional features. If the macro is absent, the feature is supported.
  5. 5. Why might #include <stdbit.h> fail with a C23 compiler?

    Language features come from the compiler, but most headers and functions come from the C library (such as glibc), which is updated separately.

Summary

  • C has been revised several times: C89/C90, C99, C11, C17 and C23 (published 2024); __STDC_VERSION__ tells you which one you're compiling.
  • C99 brought // comments, declarations anywhere, bool, <stdint.h>, designated initializers, compound literals, VLAs, inline, restrict and snprintf.
  • C11 added threads, atomics, _Generic, static_assert, alignment control and anonymous unions, and removed gets. C17 only fixed defects.
  • C23 adds bool/true/false, nullptr, constexpr, typeof, auto, [[attributes]], digit separators, binary literals, {} initialization, typed enums, #embed and ckd_add.
  • Compiler support for C23 is good in GCC and Clang, partial in MSVC; library features depend on your C library version.
  • Use C17 as a portable baseline and adopt C23 features where your toolchains allow.

Next: Best Practices and Common Mistakes