#include <stdio.h>
register int i = 10;
int main(void)
{
printf( " i = %d \n ", i );
return 0;
}
Here i declared the variable i as register. But, while compiling its showing the following error
" error: register name not specified for ‘i’ "
Why we should not use register keyword in global ?
A register
variable is a type of local variable.
It is a hint to store the value in a register for faster access.
A register variable can not be global or static.
It can be defined only in a block.
Also please format the code you post
A register
variable cannot be used as a "global" variable, because file scope variables have static storage, thus by definition they have an address. register
variables are exactly the contrary, that are variables for which you, the programmer, promise to never take their address. So combining the two makes not much sense.
BTW, the error message that you get is not very helpful. It seems that your compiler is referring to an extension that allows to fix a register
variable to a particular hardware register. If you post such an error message please also give an indication which compiler and/or platform you are using.
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