Title
Relaxed requirements for integer representations
Status
review
Section
C.7.3 [diff.basic]
Submitter
Jiang An

Created on 2026-06-04.00:00:00 last changed 5 days ago

Messages

Date: 2026-06-29.19:30:35

CWG 2026-06-26

In lieu of the above suggested resolution, CWG opted to eliminate this difference vs. C.

Possible resoluition:

Change in 6.9.2 [basic.fundamental] paragraph 11 as follows:

The types char, wchar_t, char8_t, char16_t, and char32_t are collectively called character types. The character types, bool, the signed and unsigned integer types, and cv-qualified versions (6.9.5 [basic.type.qualifier]) thereof, are collectively termed integral types. A synonym for integral type is integer type.

[Note 8: Enumerations (9.8.1 [dcl.enum]) are not integral; however, unscoped enumerations can be promoted to integral types as specified in 7.3.7 [conv.prom]. —end note]

If the bits in the value representation of an object of integer type other than bool all have value zero, the object contains the value zero (7.3.2 [conv.lval]). If the bits in the value representation of an object of type bool all have value zero, the object contains the value false.

Date: 2026-06-27.08:00:27

Suggested resolution [SUPERSEDED]:

Add a section in C.7.3 [diff.basic] as follows:

Affected subclause: 6.9.2 [basic.fundamental]
Change: C++ has relaxed rules for the representation of integer types compared to C.
[ Example: With the assumption that int has no padding bits:
  int i = 0;
  unsigned char a[sizeof(int)] = {};
  assert(memcmp(&i, a, sizeof(i)) == 0);   // guaranteed to hold in C; may fail in C++
-- end example]
Rationale: C++ has a more elaborate value model that de-emphasizes access to object representations.
Effect on original feature: Change of semantics of well-defined feature.
Difficulty of converting: Semantic transformation. Aggregate initialization should be used in lieu of memset.
How widely used: Occasionally. In particular, calloc and memset are expected to yield scalar subobjects with value 0.
Date: 2026-06-04.00:00:00

(From submission #914.)

C++ does not have a requirement that an integer value 0 is represented as all-zero bits in the value representation; C does. See C23 6.2.6.2 paragraph 3:

... For any integer type, the object representation where all the bits are zero shall be a representation of the value zero in that type.
History
Date User Action Args
2026-06-27 08:00:27adminsetmessages: + msg8619
2026-06-27 08:00:27adminsetstatus: open -> review
2026-06-04 22:21:49adminsetmessages: + msg8596
2026-06-04 00:00:00admincreate