This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
role of "register" C keyword?
- From: Basile Starynkevitch <basile at starynkevitch dot net>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 6 May 2010 14:16:38 +0200
- Subject: role of "register" C keyword?
Hello All,
What is the role of the "register" keyword [=storage class specifier]
in C (& C++) in the current GCC compiler?
IIRC, (from my human rusty memory, I don't have the documents on hand)
the current standard only requires that variable declared with the
register class should not have their adress taken thru the unary &
operator, and might have some imprecise phrasing about register being
a hint for optimisation. IIRC the C++ language might not have this
requirement (of prohibiting the & unary operator).
Long time ago (probably in the GCC 2.95 & 3.2 time frame) I would
imagine that the "register" keyword indeed affected register
allocation, in the sense that variables declared with register where
indeed & preferentially put in a machine register. In the current GCC,
I would guess it is not the case anymore (the machine register
allocation is done by optimization passes).
Of course, I am not speaking of
http://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html or
http://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html ; in both case
the register keyword is highly significant. I am just speaking of old
C code like
register int i;
for (i=0; i<10; i++) t[i]=i;
I believe nobody codes this way in 2010.
If my guessing is correct, perhaps we might add a sentence in the
documentation, something like
"The register storage class specifier keyword does not influence the
optimization and performance of generated code. It only prohibits (for
C code) the unary prefix addess-of operator &"
Perhaps the place to add that sentence [if it is correct] might be
http://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html or
http://gcc.gnu.org/onlinedocs/gcc/Qualifiers-implementation.html or
http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
BTW, I might have read somewhere than in future C & C++ standards the
register keyword might change its meaning or be obsolete... Am I
dreaming, or is there some evolution to expect?
Comments are welcome.
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***