Skip to content

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

@eisenwave

Description

@eisenwave

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.

Metadata

Metadata

Assignees

Labels

P3-OtherTriaged issue not in P1 or P2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions