Search code examples
cstandardsc23

Is the C23 standard backward compatible?


Can C17 code be interpreted as C23 code? If not, what are the breaking changes?


Solution

  • No, C23 is not fully backwards compatible. Not all C17 programs can be compiled as C23 programs.

    Among other significant changes, C23 introduces new keywords and declaration specifiers. C17 programs that use those identifiers cannot be interpreted as C23 programs.

    For example, all of the following are valid in C17 programs, but are invalid in C23 programs.

    int* nullptr = 0;
    int true = 1;
    int bool = 0;
    int constexpr = 1;
    void static_assert() { /* ... */ }
    

    More dangerously, the following code snippets have different meanings in C17 vs C23

    auto d = 1.5;   // C23: `d` has type `double` 
                    // C17: `d` has type `int`
    
    void foo();     // C23: equivalent to `void foo(void);`
                    // C17: non-prototype function declaration
    

    For a more complete account of major changes in C23, see Annex M.2 of N3096 (latest working draft of C23, 2023-04-01).