Register variable ;
Its simply a request to the compiler that perticular variable will be used heavly and place it in CPU registers.
But there are lots of gotchas here
1) Which data can be held in registers depend on register size. Normaly its size of word or interger elemnet max. Though some system do have the registers capalbe of holding the floating point values in registers.
2) Though its a request but once you declare a variable as register it may go to the register. So you cannot use its address in your program. It means you can not use & operator on the register variable. If you try to do the same you are welcomed with compiler error.
3) More over you declared a variable regiter and system choose to put it in the register. It may actually slow down your system. Because no of registers are limited in numbers and you have reserved some of them, now the variable you have placed in the register is not modifying enough so its like wasting a resource.
4) You can ask when to use register type. Plain answer is never.
In earlier days it was a value addtion to the 'C' language as earlier compiler were not using register at all implicitly.
But mordern compilers are smart enough to decide which value is to be placed where. Actully its a rare event that by putting some value in register can increase the efficeny of your program.
Some of todays compiler simply ignore the register keyword as its perfecly inline with reiger definition "Its a request not an order".
No comments:
Post a Comment