Sourabh Daptardar wrote:
>
On Jun 6, 12:52 am, Victor Bazarov <v.Abaza...@comAcast.netwrote:
>Think about it... What would that mean if you declare one member
'register' and another member 'extern'? And if an instance of theclass
is declared 'static' (or simply outside of any function), what should
compiler do if any of the datamembersare declared 'auto'? Should it
ignore the specifiers? What's the point of allowing them, then?
Lets consider only the 'register' case.
When we use a register storage specifier for a non-member variable :
register int var;
It is a request ( which may not be honoured ) to the compiler to
assign a register for the variable -- it might speed up the
calculations.
At this point in hardware advancements, in compiler advancements, and
the desire to keep our source code portable, what meaning (to you or to
anyone else) would such a request have? If it may not be honoured, what
value does there exist to keep this in the language except to allow the
legacy programs that were written when those specifiers had meaning, to
still compile? Let's take the opposite situation; does the *absence* of
the specifier prevent the compiler from placing the variable in a
register to speed up calculations? No. What would then be the point?
Why is not allowed for class members ? If I there is a class member
variable which is going to be heavily used in calculations, it might
be worthwhile.
How can a member variable be placed in a register and the whole object
be placed elsewhere? For some local calculations, a _copy_ of the
member variable can certainly be placed in a register (and the compiler
will take care of updating the member as needed). So, what would the
"register" specifier do, what would its *purpose* be?
If we have one class member with register storage specifier and other
without it ; both are stored in the primary memory but only the first
one is brought in the register. On memory reference to that location
there will be a write-back.
Uh... Didn't you just say that "register" may not be honoured? Just
like "inline" (in this particular sense, we're not talking linkage
here), "register" would be but a hint to the compiler. But doesn't any
modern compiler know already enough how to do its job to not need our
hints about what to place where? Or are you proposing that for
stand-alone variables "register" is only a hint, but for data members
it's made a hard directive?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask