Re: Keyword register
From: Jack Klein (jackklein_at_spamcop.net)
Date: 11/23/04
- Next message: Howard: "Re: constructor"
- Previous message: Richard Herring: "Re: Container << Object"
- In reply to: Ioannis Vranos: "Keyword register"
- Next in thread: Branimir Maksimovic: "Re: Keyword register"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Howard: "Re: constructor"
- Previous message: Richard Herring: "Re: Container << Object"
- In reply to: Ioannis Vranos: "Keyword register"
- Next in thread: Branimir Maksimovic: "Re: Keyword register"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|