Re: Keyword register

From: Jack Klein (jackklein_at_spamcop.net)
Date: 11/23/04


Date: Tue, 23 Nov 2004 11:55:58 -0600

On Tue, 23 Nov 2004 12:29:45 +0200, Ioannis Vranos
<ivr@remove.this.grad.com> wrote in comp.lang.c++:

> 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 offers no help to an
> implementation, it is free to ignore it. And this happens widely, all my
> C++ compilers in my platform ignore this keyword.

This is true in C++, but is one of the differenced between C++ and C.
It is not legal in C to take the address of an object defined with the
register storage class, whether the compiler ignores the hint or not.

> Also the use of register provides the additional guarantee that we do
> not get the address of this variable which may indeed help an
> implementation to optimise the variable access further, which was the
> original purpose of its introduction after all.
>
> So why we should not use register?
>
> An implementation taking it into account means that the keyword helps it
> indeed, otherwise the implementation *should* ignore it.

You have already gotten a lot of good replies, and in general I agree
with them. In general, a programmer, particularly an applications
level programmer, should not use the register keyword.

It is in fact much like any other source code optimization. It should
not be used at all initially, unless you doing things like writing
hardware-level drivers or interrupt service routines, and probably not
even then.

Once you have a program that operates correctly but more slowly than
desired, you can apply tools like profilers to find out where the
bottlenecks are. Then, and only then, apply source code optimizations
like selective use of the register keyword to see if it improves
performance.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html


Relevant Pages

  • Re: Register keyword and "as if" rule...
    ... its way to take a full 10 minutes every time a "register" declared ... Then my compiler is still C compliant, ... keyword if they want their code to run smoothly on all implementations: ... Optimization hints in general are not nearly so important as they were ...
    (comp.lang.c)
  • Re: Can I pass OpenArgs to multiple instances of the same form?
    ... As you found, using the New keyword to open a form does not give you the option of OpenArgs, so you will be looking for alternate approaches. ... I want to be able to open a Bank1 register ... form and a Bank2 register form at the same time, ...
    (microsoft.public.access.forms)
  • RE: Internet Keyword System..
    ... The Chinese mainland has been pursuing domestic technologies rather than ... Those who failed to register ... Subject: Internet Keyword System.. ... Internet Keyword Service was launched by CNNIC (China ...
    (Security-Basics)
  • Keyword register
    ... It was advised in this newsgroups that we should avoid the use of ... C++ compilers in my platform ignore this keyword. ... Also the use of register provides the additional guarantee that we do ... implementation to optimise the variable access further, ...
    (comp.lang.cpp)
  • Re: How does this make you feel?
    ... If it is possible to offload work from the programmer in such a common case, ... the end user doesn't care in the least about computer architecture aesthetics. ... behaviour of a conventionally conceieved register. ... advocating a change in the way registers are conceived from a CPU ...
    (comp.arch)