GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 7 of 453    Print  
When should the register modifier be used? Does it really help?
The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions on the use of the register modifier.
First, the variable must be of a type that can be held in the CPU’s register. This usually means a single value of a size less than or equal to the size of an integer. Some machines have registers that can hold floating-point numbers as well.
Second, because the variable might not be stored in memory, its address cannot be taken with the unary & operator. An attempt to do so is flagged as an error by the compiler. Some additional rules affect how useful the register modifier is. Because the number of registers is limited, and because some registers can hold only certain types of data (such as pointers or floating-point numbers), the number and types of register modifiers that will actually have any effect are dependent on what machine the program will run on. Any additional register modifiers are silently ignored by the compiler.
Also, in some cases, it might actually be slower to keep a variable in a register because that register then
becomes unavailable for other purposes or because the variable isn’t used enough to justify the overhead of loading and storing it.
 So when should the register modifier be used? The answer is never, with most modern compilers. Early C compilers did not keep any variables in registers unless directed to do so, and the register modifier was a valuable addition to the language. C compiler design has advanced to the point, however, where the compiler will usually make better decisions than the programmer about which variables should be stored in registers.
In fact, many compilers actually ignore the register modifier, which is perfectly legal, because it is only a hint and not a directive.



  
Total Answers and Comments: 1 Last Update: October 04, 2007   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: srinivasarao
 
If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access from there, so as fast execution. Some times the registers are not available, because of  the same register are used by some other variable at that time it acts as auto variable.

Above answer was rated as good by the following members:
samcorp3
October 04, 2007 23:40:13   #1  
srinivasarao        

RE: When should the register modifier be us...
If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access from there so as fast execution. Some times the registers are not available because of the same register are used by some other variable at that time it acts as auto variable.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions 
Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the 

Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in  
Latest Answer : But isnt like the constant variables will be stored by in ROM (read only memory).Then how can the some process other than the code can change the value of const volatile ...

As described at the beginning of this chapter, some compilers for PC compatibles use two types of pointers. near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits long and 
Latest Answer : atthe time of 8086 , the processor operate in real modebt after that as more processor develop then there are two type of mode.2nd one is protected mode.in real mode the processor canuse only 1mb bt in protected mode one can use memory more then 1mb.as ...

A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage.There are five types of storage classes 1)auto   2)static   3)extern  

A large program is subdivided into a number of smaller programs or subprograms. Each subprogram specifies one or more actions to be performed for a large program.such subprograms are functions. The 
Latest Answer :    C program uses Both built in function and function(which is also called user defined)     Built in function means the declaration and defination of afunction is already known to the compiler.       ...

Latest Answer : By saying register to a Variable , you are just suggesting the compiler put in register.Compiler is the best person to decide, which var will go in register. I believe , we should not use register , it may confuse compiler.auto is just stack variables, ...
Read Answers (3) | Asked by : Renuka

Latest Answer : Apart from the above mentioned ones, the maximum number that could be stored in registers depends solely on the register size. The memory cannot be dereferenced by an 'addressof' operator for register variables. ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape