Question Details

No question body available.

Tags

c language-lawyer c89

Answers (1)

May 29, 2026 Score: 2 Rep: 235,169 Quality: Medium Completeness: 80%

In the code block where you state:

Is it guaranteed that a==2 and b==6

Up to C11, yes. Starting with C23, no.

Section 3.6 of C89 states the following:

A full expression is an expression that is not part of another expression. Each of the following is a full expression: an initializer; the expression in an expression statement; the controlling expression of a selection statement ( if or switch ); the controlling expression of a while or do statement; each of the three expressions of a for statement; the expression in a return statement. The end of a full expression is a sequence point.

And appendix A.2 regarding sequence points lists the following:

The end of a full expression: an initializer (3.5.7);

Which means there's a sequence point between the initialization of a and the initialization of b under C89.

The wording changed in C99 and C11. In particular, section 6.7.6p3 of C11 regarding declarators (i.e. a declaration of an object along with its initializer) states:

A full declarator is a declarator that is not part of another declarator. The end of a full declarator is a sequence point.

And appendix C regarding sequence points lists:

The end of a full declarator: declarators

So the same applies up to C11.

Starting in C23 is where things change. Specifically, the bolded passage from 6.7.6p3 above was removed as well as the line from appendix C above.

So the above guarantee no longer applies as of C23.


Note that the following passage from 6.7.9p23 of C11 / 6.7.10p24 of C23 does not apply:

The evaluations of the initialization list expressions are indeterminately sequenced with respect to one another and thus the order in which any side effects occur is unspecified

As that only applies to aggregates as per C11 6.7.9p12 / C23 6.7.10p13:

The rest of this subclause deals with initializers for objects that have aggregate or union type.