473,499 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

register variables....

ashitpro
542 Recognized Expert Contributor
Hello again,

look at the following statements

register int i;
int* b = &i; // valid in C++, but not in C

when we use "register" specifier, it's a request to compiler that to put the variable in fast registers.
Now, If we assume that "i" has got stored in register, I am wondering what will be value of "b".
Do we really have addresses to CPU registers?

Regards
Ash
Oct 29 '08 #1
2 1703
arnaudk
424 Contributor
The compiler doesn't have to honour your request for a CPU register, and as far as I know most modern compilers don't as the speed gained is negligible with modern computers. Also, ANSI C does not allow for taking the address of a register object but this restriction does not apply to C++.
Oct 29 '08 #2
Banfa
9,065 Recognized Expert Moderator Expert
Note since the compiler is free to choose if it honours the register keyword and if you take the address of a variable it must be in an addressable location and most processor registers are not addressable locations.

So using C++ if you take the address of a register variable the most likely outcome is that the compiler will choose to place the variable in memory anyway so that it can be addressed.

TBH the register keyword really exists from before the time of optimising compilers when the programmer had to hand optimise the code as a way of indicating to the compiler which variable to place in registers. Today it is best to let the optimiser make this decision, it is likely to make a better decision that you.
Oct 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2241
by: Alex | last post by:
I apoligise in advance if this is an os or platform based question, I don't know. I was wondering how register integers (and other types of register variables) are managed by c++. For example,...
10
15636
by: ajay | last post by:
some say floats can't be stored in register. size of int and float are same ( on some machine am i Wrong?) so if int can be delcared as register than why not float(where in and float are of same...
14
7888
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
16
3721
by: alakesh.haloi | last post by:
Hi All Is there a limit on the number of register variables that can be declared and initialized in a C program on a particular hardware platform? If you define more number of register variables...
16
2435
by: junky_fellow | last post by:
what is the purpose of declaring a register variable ? why can't we find the address of register variable ?
7
5132
by: int main(void) | last post by:
Hi all, I know that register variables work fine at block scope. I tried putting a register variable in file scope, like this, #include <stdio.h> register int a = 2; int main(void) {...
33
3231
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
28
3518
by: sowmiyakc18 | last post by:
Please clear my doubt. When do we declare a variable to be a register variable? What is its significance? What are the conditions to be adhered to when register variables are passed between...
26
2189
by: Vashna | last post by:
Hi Group, I have a doubt about register variables. I know that if we have a variable used very frequently in a function, then provided we never apply the & function to it, we can define it as...
7
1833
by: RANNA | last post by:
Say the CPU has only AL, BL, CL, DL or eight 8 bit registers, and if want to declare 10 register variables in my code, is it possible to do it?
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.