473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Howmay varaibles can be declared as register?

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?
Oct 20 '08 #1
7 1825
RANNA wrote:
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?
You can declare as many register variables as you want. The compiler is
free to ignore any of those declarations; it's even free to ignore all
of them.

If all 10 variables must exist at the same time, the compiler can't
possibly implement them all as registers on such a machine. However,
keep in mind that the compiler has a lot of freedom to rearrange your
code, so long as the rearranged code has the same behavior as the
original. If it finds a rearrangement such that two of your variables
are never storing a value as the same time, it might implement both of
them as using the same register. If it finds two such pairs, it might be
able to put all ten variables into 8 registers. However, it's more
likely to ignore some or all of your 'register' declarations, and make
up it's own mind about which variables should be stored in registers.
When doing so, it will probably make a better choice than the one that
you made.

If it's really important to you to control such things, the C language
is the wrong one to use. You probably should use some sort of assembly
language.
Oct 20 '08 #2
RANNA wrote:
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?
Yes. Declare a hundred if you like, or a thousand.

But it probably won't do you any good. Declaring a variable with
the `register' storage class does two things: It prevents you from
forming any pointers to the variable, and it suggests that access to
the variable should be as fast as possible. Note that "suggests" is
not the same as "commands," and the compiler may choose to ignore
your suggestion. Nowadays, few compilers pay attention to it, so
you're left with only the first effect.

In the Bad Old Days, `register' could have a significant effect
on the performance of a program. Note that "significant" is not
necessarily the same as "beneficial;" sometimes adding `register'
made the program slower ...

--
Er*********@sun.com
Oct 20 '08 #3
James Kuyper <ja*********@verizon.netwrites:
RANNA wrote:
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?

You can declare as many register variables as you want. The compiler is
free to ignore any of those declarations; it's even free to ignore all
of them.
<pardon-my-pedantry>
Of course what is meant is that the compiler may ignore the 'register'
storage class specifiers, not that it may ignore the declarations.
</pardon-my-pedantry>
[...]
Nov 10 '08 #4
In article <kf*************@alumnus.caltech.edu>,
Tim Rentsch <tx*@alumnus.caltech.eduwrote:
>James Kuyper <ja*********@verizon.netwrites:
>RANNA wrote:
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?

You can declare as many register variables as you want. The compiler is
free to ignore any of those declarations; it's even free to ignore all
of them.

<pardon-my-pedantry>
Of course what is meant is that the compiler may ignore the 'register'
storage class specifiers, not that it may ignore the declarations.
</pardon-my-pedantry>
<super-pedant-mode>

Someone will come along and point out that the other key thing about
register variables is that you can't take their address.

So, the compiler is not free to ignore the 'register' keyword (as if you
had done: #define register)
in the sense that if you later try to apply the & to such a variable, it
has to flag it.

Nov 10 '08 #5
In article <gf*********@news.xmission.com>,
Kenny McCormack <ga*****@shell.xmission.comwrote:
><super-pedant-mode>
>So, the compiler is not free to ignore the 'register' keyword (as if you
had done: #define register)
in the sense that if you later try to apply the & to such a variable, it
has to flag it.
Ha, call that super-pedantry?

A compiler is free to issue any diagnostics it likes for legal code.
So it could warn every time the address of *any* variable is taken,
and it would then be free to ignore "register".

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 10 '08 #6
Richard Tobin wrote:
Kenny McCormack <ga*****@shell.xmission.comwrote:
><super-pedant-mode>
>So, the compiler is not free to ignore the 'register' keyword
(as if you had done: #define register) in the sense that if you
later try to apply the & to such a variable, it has to flag it.

Ha, call that super-pedantry?

A compiler is free to issue any diagnostics it likes for legal
code. So it could warn every time the address of *any* variable
is taken, and it would then be free to ignore "register".
No, it isn't free to ignore 'register'. It is free to avoid the
act of assigning a register. It is not free to allow access to the
address of that variable.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Nov 10 '08 #7
CBFalconer said:
Richard Tobin wrote:
>Kenny McCormack <ga*****@shell.xmission.comwrote:
>><super-pedant-mode>
>>So, the compiler is not free to ignore the 'register' keyword
(as if you had done: #define register) in the sense that if you
later try to apply the & to such a variable, it has to flag it.

Ha, call that super-pedantry?

A compiler is free to issue any diagnostics it likes for legal
code. So it could warn every time the address of *any* variable
is taken, and it would then be free to ignore "register".

No, it isn't free to ignore 'register'.
Under the conditions that Richard Tobin stated, it is.
It is free to avoid the act of assigning a register.
Yes.
It is not free to allow access to the address of that variable.
Wrong. If a program attempts to take the address of an object whose
identifier is register-qualified, a constraint has been broken, and this
requires a diagnostic message. If the implementation diagnoses *every*
occurrence of an address being taken, then it will diagnose the taking of
the address of an object whose identifier is register-qualified. It is
then free to produce an executable program, or not - either is legal. The
behaviour of such a program, if produced, would of course be undefined.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 10 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
12
by: Ioannis Vranos | last post by:
Just some thought on it, wanting to see any explanations. It was advised in this newsgroups that we should avoid the use of keyword register. However it is a language feature, and if it...
4
by: Cheng Mo | last post by:
I know global varaibles should always be avoided. I asked this question just for deep insight about C++. If global variables are distributed among different source code files, what's the...
3
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,...
13
by: Shankar Agarwal | last post by:
I was trying to use a variable whose value is temporary and i don't want it to go to the memory for performance reasons. Is there a way to specify the variable like that so that any assignment to...
14
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
2
by: Corinne | last post by:
Hi everyone: I have created a test.aspx page. (Visual studio 2005) I want to declare some variables to use in a IF statement to assign other variables specific values. I keep on getting...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...
0
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...

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.