Skip to content

CWG3197 [diff.basic] Entry for more relaxed requirements of integer representations in C++ #914

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [diff.basic]

Link to reflector thread (if any):

Issue description:

[basic.fundamental] p5 specifies that for an N-bit integer type, there're N binary coefficients contributing to the integer value. However, there's no direct relation between N constituent bits and these N coefficients specified by the C++ standard.

On the contrary, such relation is present in C, at least since C99. WG14 N691 bounded the binary coefficients to the bit values.

Per discussion in #912 (comment), such difference seems to be intended. Perhaps we should have entry in [diff.basic] for this.

E.g.

#include <stdint.h>
#include <string.h>

void f() {
  int32_t n = {};
  unsigned char buf[sizeof(int32_t)] = {};
  bool b = memcmp(&n, &buf, sizeof(int32_t)) == 0; // guaranteed to be true in C, not guaranteed in C++
}

Suggested resolution:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions