Title
Incorrect statement about enumerators for C23
Status
open
Section
C.7.6 [diff.dcl]
Submitter
Hubert Tong

Created on 2025-12-11.00:00:00 last changed yesterday

Messages

Date: 2025-12-11.08:16:01

Possible resolution:

Change in C.7.6 [diff.dcl] paragraph 12 as follows:

Affected subclause: 9.8.1 [dcl.enum]
Change: In C++, the type of an enumerator is its enumeration. In C, the type of an enumerator is int or another integer type.
[Example 10:
  enum e { A };
  void f() {
    auto x = A;
    int *p = &x;   // valid C, invalid C++
  }
  sizeof(A) == sizeof(int)  // in C
  sizeof(A) == sizeof(e)    // in C++
  /* and sizeof(int) is not necessarily equal to sizeof(e) */
end example]
Rationale: In C++, an enumeration is a distinct type.
Effect on original feature: Change to semantics of well-defined feature.
Difficulty of converting: Semantic transformation.
How widely used: Seldom. The only time this affects existing C code is when the size of an enumerator is taken. Taking the size of an enumerator is not a common C coding practice.
Date: 2025-12-11.00:00:00

(From submission #828.)

After C++ was rebased on C23, the statement in C.7.6 [diff.dcl] paragraph 12 that the type of enumerators in C is int is no longer correct (see WG14 N3029 and WG14 N3030).

History
Date User Action Args
2025-12-11 08:16:01adminsetmessages: + msg8435
2025-12-11 00:00:00admincreate