Skip to content

[basic.fundamental] Should we remove Note 1 on int having the "natural width"? #6825

Open
@Eisenwave

Description

@Eisenwave
Member

Plain ints are intended to have the natural width suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs.

[basic.fundamental] Note 1

I feel like this note is not doing much good at this point. Firstly, this sounds a lot like a Recommended practice paragraph, not like a note.

Besides that, it's not what implementers typically do, or should do. The "natural width" is the width of the general purpose register or the width of pointers; anything less will usually require zero- or sign-extension:

char* advance(char* p, int x) {
    return p + x;
}
char* advance(char* p, long long x) {
    return p + x;
}

Clang emits:

advance(char*, int):
  movsxd rax, esi
  add rax, rdi
  ret
advance(char*, long long):
  lea rax, [rdi + rsi]
  ret

If implementers respected this note, int should be a 64-bit type on x86_64, which would make it "natural" and drop sign extensions. I don't believe this is useful or desirable; the general approach is to cap the int size at 32-bit, even if this makes it less natural and requires additional operations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Eisenwave

        Issue actions

          [basic.fundamental] Should we remove Note 1 on `int` having the "natural width"? · Issue #6825 · cplusplus/draft