A
aruna
What is the disadvantage of using register
storage class specifier?
storage class specifier?
What is the disadvantage of using register
storage class specifier?
aruna said:What is the disadvantage of using register
storage class specifier?
Lew Pitcher said: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.
Keith Thompson said: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).
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.
What is the disadvantage of using register
storage class specifier?
Christopher Benson-Manica said: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?
Christian said:What is the disadvantage of using register
storage class specifier?
It requires typing seven characters, [...]
Yes, if gcc is a real implementation. No, if you don't count registerizationChristopher Benson-Manica said: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?
Eric said:Christian said:What is the disadvantage of using register
storage class specifier?
It requires typing seven characters, [...]
Christian is a *fast* typist ...
In said:What is the disadvantage of using register storage class specifier?
Christian said:It requires typing seven characters, and it disallows usage of the
address operator. In some cases, it causes undefined behaviour.
In said:I would say nine characters.
Dan said:The same as its advantage: the compiler might take it seriously.
If the compiler is good at performing optimisations on its own, this
is a disadvantage. If the compiler doesn't even try to optimise, this is
an advantage.
To a good optimising compiler, forcing a variable to be kept in a register
for the whole duration of a function's execution is usually a disadvantage
because it can decide better when keeping that variable in a register
makes sense. Fortunately, such compilers usually ignore this part of the
register keyword semantics and only retain the "no unary & operator" bit.
Dan said:#define regist register
and Christian is right ;-)
Dan
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.