What is the disadvantage of using register
storage class specifier? 14 7909
aruna wrote: What is the disadvantage of using register storage class specifier?
Do your own homework, you will get better answers
in a book than you will get here.
--
Thomas.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
aruna wrote: What is the disadvantage of using register storage class specifier?
In my opinion, the primary disadvantage is that you can't take the
address of a register variable.
Again, my opinion, but the 'register' storage class doesn't provide much
of an advantage when it is used: the compiler is permitted to ignore it
when selecting placement of variables, compiler optimization of
generated code may do a better job of optimizing placement than the
programmer can, and the language imposes restrictions on the use of
variables defined as register.
- --
Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFAj9fCagV FX4UWr64RApRVAK Cfs0M3p2yECKZbW Jd4Ypw0fj91vwCf Rlsu
IT1RBBQIMrWWkTL jc1yVdTY=
=L0q5
-----END PGP SIGNATURE-----
Lew Pitcher <Le*********@td .com> writes: aruna wrote: What is the disadvantage of using register storage class specifier? In my opinion, the primary disadvantage is that you can't take the address of a register variable.
One could argue that that's an advantage. The "register" specifier is
a way of asserting to the compiler that a given variable won't have
its address taken. Theoretically a compiler could use that
information for optimization, even if it doesn't use it for its
original intent (storing the variable in a CPU register).
If my goal were to give the compiler as much information as possible,
I might even use a "register" specifier on *every* variable whose
address isn't taken. But the result wouldn't be pretty, and it
probably wouldn't do much good; any decent modern optimizing compiler
should be able to figure this out for itself.
Again, my opinion, but the 'register' storage class doesn't provide much of an advantage when it is used: the compiler is permitted to ignore it when selecting placement of variables, compiler optimization of generated code may do a better job of optimizing placement than the programmer can, and the language imposes restrictions on the use of variables defined as register.
That's certainly the common wisdom, and I suspect compiler
implementers take that into account when deciding how much attention
to pay to "register" specifiers (i.e., not much). I've even read that
"register" can hurt optimization by interfering with the compiler's
own analysis, but I don't know if that's actually true.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Keith Thompson <ks***@mib.or g> spoke thus: One could argue that that's an advantage. The "register" specifier is a way of asserting to the compiler that a given variable won't have its address taken. Theoretically a compiler could use that information for optimization, even if it doesn't use it for its original intent (storing the variable in a CPU register).
Setting aside theory, do any real implementations optimize based on
the fact that a given variable's address is never taken, aside from
placing that variable in a register or not?
to pay to "register" specifiers (i.e., not much). I've even read that "register" can hurt optimization by interfering with the compiler's own analysis, but I don't know if that's actually true.
I imagine that "register" can only hurt optimization as much as the
compiler lets it. It's a hint that I imagine is nowadays routinely
ignored by compilers.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
In article <a2************ **************@ posting.google. com>, ar********@yaho o.co.in (aruna) wrote: What is the disadvantage of using register storage class specifier?
It requires typing seven characters, and it disallows usage of the
address operator. In some cases, it causes undefined behaviour.
Now ask for the advantages...
In article <c6**********@c hessie.cirr.com >,
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote: Keith Thompson <ks***@mib.or g> spoke thus:
One could argue that that's an advantage. The "register" specifier is a way of asserting to the compiler that a given variable won't have its address taken. Theoretically a compiler could use that information for optimization, even if it doesn't use it for its original intent (storing the variable in a CPU register).
Setting aside theory, do any real implementations optimize based on the fact that a given variable's address is never taken, aside from placing that variable in a register or not?
First, real implementations are more clever; even if the address of a
variable is taken, it is often possible to determine the set of accesses
to the variable exactly (this would be in practise more important for
C++ compilers + trivial classes + inline functions, but many compilers
implement both C and C++).
Second, if you know exactly all accesses to a variable, then you also
know that there is no aliasing, and that will help a lot. For example:
struct { int x; int y; int z; } t;
int *p;
t.x = 1; *p = 2;
t.y = t.x + 1; *p = 3;
t.z = t.x + t.y + 1; *p = 4;
Even if t.x, t.y and t.z are not in registers, the compiler may be able
to find that t.x, t.y and t.z are set to 1, 2 and 4, and *p needs only
be set once.
Christian Bau wrote: In article <a2************ **************@ posting.google. com>, ar********@yaho o.co.in (aruna) wrote:
What is the disadvantage of using register storage class specifier?
It requires typing seven characters, [...]
Christian is a *fast* typist ...
-- Er*********@sun .com
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:c6******** **@chessie.cirr .com... Keith Thompson <ks***@mib.or g> spoke thus:
One could argue that that's an advantage. The "register" specifier is a way of asserting to the compiler that a given variable won't have its address taken. Theoretically a compiler could use that information for optimization, even if it doesn't use it for its original intent (storing the variable in a CPU register).
Setting aside theory, do any real implementations optimize based on the fact that a given variable's address is never taken, aside from placing that variable in a register or not?
Yes, if gcc is a real implementation. No, if you don't count registerization
as an optimization. I have bug issues pending against a commercial compiler,
where taking an address inhibits optimization more than it should.
Eric Sosman wrote: Christian Bau wrote: In article <a2************ **************@ posting.google. com>, ar********@yaho o.co.in (aruna) wrote:
What is the disadvantage of using register storage class specifier?
It requires typing seven characters, [...]
Christian is a *fast* typist ...
Indeed. Can't say much about readability though. Its like
programming while pissed ;)
rgistr cst unsigd sht x; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ravi_shankar |
last post by:
I know java,but I am just beginner in C.I have some confusions
regarding extern storage specifier and default storage class specifier
for a variable when it has file scope that is ,when it is not
defined within
any block
--
Posted via http://dbforums.com
|
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 size) ?
tx
Ajay
|
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 than the
processor has, how is it handled by the C compiler?
regards
|
by: orium69 |
last post by:
hi everyone, i'm wondering if there is a way to have sure that a
variable is allocated in the cache, after its declaration with
"register"? Tks!
|
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 full 10 minutes every time a "register" declared
variable is read from or written to. Besides this lag, everything else
runs as expected. Then my compiler is still C compliant, aye?
If so, then it is unwise for any programmer to ever use the...
| |
by: sunny |
last post by:
Hi
C Ref Man says
" The typedef specifier does not reserve storage and is called a
storage class specifier only for syntactic convenience "
does this mean storage specifier for "user specific storage area" ?
ie. flexibity to provided to create user defined storage class
specifier.
|
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 a
register variable and this will make it much faster to access.
Now the question is: obviously there are only a fixed number of
registers in our CPU, maybe 6 or something. So how do we choose which
|
by: Sensei |
last post by:
Hi again!
I have recently encountered an old code in K&R style which declared
function parameters as register. That puzzles me, and I know this is
implementation defined, and depends on architecture, compiler and so
on. But my question is, how can be a parameter made "faster" (6.7.1,
with note 103).
On Intel and similar implementations all parameters are, as far as I
know, pushed into the stack. On PPC they can be passed through
|
by: JOYCE |
last post by:
Look the subject,that's my problem!
I hope someone can help me, thanks
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |