Advertisements
I am trying to simplify the following fragment of code:
void foo() {
register int r0, r1, r2, r3;
r0 = 0;
r1 = 0;
r2 = 0;
r3 = 0;
}
by introducing constant-size array and a loop over it
void foo() {
register int r[4];
for (int i = 0; i < 4; i++) {
r[i] = 0;
}
}
What I noticed is that it is not supported by some versions of compilers. Why?
- Clang 13
error: address of register variable requested
https://godbolt.org/z/v7TKW8f68 - Clang 12 everything is ok https://godbolt.org/z/63vKE1nY4
- GCC 13
error: address of register variable 'r' requested
https://godbolt.org/z/r6d86Wo7r
>Solution :
If the array object has register storage class, the
behavior is undefined..