Register storage class
Automatic variables are allocated in the main memory of the processor; accessing this memory location for computation will take a long time.
when we required optimising the execution time, move the critical variable to the processor register. this can be done by using the register keyword.
when storage class is register, a compiler is instructed to allocate a register for this variable.
scope of the register variable is same as auto variable.
NOTE: Allocation of register is not guaranteed always, it depends on number register available in processor and number register used for manipulation. if you define 4 variable as register storage class and and processor has only 2 register for variable allocation, then compiler will allocate 2 variable in registers and treat the remaining 2 variable as auto variable. therefore usage of register keyword should should be justified and cross checked with disassembly weather register is allocated or not.
Comments