When defining a variable in the following manner:
static register int a1 = 0;
we get the error:
error: multiple storage classes in declaration specifiers
Is there any fundamental reason for this error? Why can't a variable be both stored in a register, and also be initialized only at start up/first call? It is possible to attach the register storage class to a global variable. <- edit: not true
The standard does not allow use of more than one storage-class specifier in a declaration.
From the C99 Standard:
6.7.1 Storage-class specifiers
1 storage-class-specifier:
typedef extern static auto register2 At most, one storage-class specifier may be given in the declaration specifiers in a declaration.
If a compiler implemented what you wanted faithfully then it would tie up a CPU register for the length of your program. That's hardly practical.
Remember that register is only advisory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With