Skip to main content

Register storage class

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

Popular posts from this blog

CAN INTERVIEW QUESTIONS

Qualifiers and Modifier in C

RTOS Real time operating system interview questions

CAN INTERVIEW QUESTIONS 2

What is UDS protocol

Memory mapping in c

TOP IOT PLATFORMS