Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Eisenwave opened this issue Feb 26, 2024 · 0 comments

Comments

@Eisenwave
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant