Is the C23 standard backward compatible?

438 views Asked by At

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

2

There are 2 answers

3
Brian61354270 On BEST ANSWER

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).

9
Surge On

C23 has not been formally approved yet as far as I know, but based on the proposed changes, yes, there is backward compatibility with C17. You will have to remove features only if you relied on very old standards like C89. (Trigraphs, old style function definitions, etc.) But those are not relevant to modern C. Look for obsolete features in the latest proposal.

Update: Yes, if you're looking for some nitpicky answer as the one above, then of course you can write code in C17 that will not compile in C23, say with weird keywords, or if you define your own macro for true and false. But if you're looking for a common-sense answer, then C17 code will compile in C23 in (virtually) all cases. Nobody uses variable names like constexpr.

Minirant: Stackoverflow is made a lower quality space by insisting on irrelevant edge case nitpicking. Users here want to learn, not to read legal documents. At least, that's why I'm here. Precision has its place, but not if it obscures important facts.