register Variables in C

By: Grenfel  

A register declaration advises the compiler that the variable in question will be heavily used. The idea is that register variables are to be placed in machine registers, which may result in smaller and faster programs. But compilers are free to ignore the advice.

The register declaration looks like

   register int  x;
   register char c;
and so on. The register declaration can only be applied to automatic variables and to the formal parameters of a function. In this later case, it looks like
   f(register unsigned m, register long n)
   {
       register int i;
       ...
   }
In practice, there are restrictions on register variables, reflecting the realities of underlying hardware. Only a few variables in each function may be kept in registers, and only certain types are allowed. Excess register declarations are harmless, however, since the word register is ignored for excess or disallowed declarations. And it is not possible to take the address of a register variable, regardless of whether the variable is actually placed in a register. The specific restrictions on number and types of register variables vary from machine to machine.


Archived Comments

1. abookzrar
View Tutorial          By: abookzrar at 2017-05-16 03:37:52

2. WayneNub
View Tutorial          By: WayneNub at 2017-04-27 22:10:43

3. If i give register int a[100], what will happen? Say if 10 registers are available in the hardware,
View Tutorial          By: ramkumar at 2017-01-28 09:41:23

4. Lyrica Ancef
View Tutorial          By: Lyrica AncefSP at 2016-11-20 05:05:49

5. RichardJal
View Tutorial          By: RichardJal at 2015-08-27 04:26:05

6. EruroErardDot
View Tutorial          By: EruroErardDot at 2015-04-02 12:06:13

7. SitsCistmix
View Tutorial          By: SitsCistmix at 2013-05-19 21:23:45

8. Can you provide some more specific application of keyword 'register' ,please?
View Tutorial          By: Rushikesh at 2012-01-15 18:23:36


Most Viewed Articles (in C )

Latest Articles (in C)

Comment on this tutorial