Description
Plain
int
s 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.
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