473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storage class specifier of class members

Why is register storage specifier not allowed for class member
variables?

<snip>
ISO standard : Section 9.2 ; point 6 :
-6- A member shall not be auto, extern, or register.
</snip>

I believe it is not related to object storage being contiguous,
discontiguous or contiguous with gaps.

Can some one throw light on this ?

Regards,
Sourabh
Jun 27 '08 #1
6 2319
Sourabh Daptardar wrote:
Why is register storage specifier not allowed for class member
variables?

<snip>
ISO standard : Section 9.2 ; point 6 :
-6- A member shall not be auto, extern, or register.
</snip>

I believe it is not related to object storage being contiguous,
discontiguous or contiguous with gaps.

Can some one throw light on this ?
Think about it... What would that mean if you declare one member
'register' and another member 'extern'? And if an instance of the class
is declared 'static' (or simply outside of any function), what should
compiler do if any of the data members are declared 'auto'? Should it
ignore the specifiers? What's the point of allowing them, then?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2


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.

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.

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.

Regards,
Sourabh
Jun 27 '08 #3
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
Jun 27 '08 #4
Hi!

Victor Bazarov schrieb:
>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.
[snip]
But doesn't any
modern compiler know already enough how to do its job to not need our
hints about what to place where?
Right. The compiler always copies data from memory into registers.
Especially for heavy use. There is no need to and no gain from
specifying "register". Not even for local variables (anymore).

And if "register" would make a difference then this difference would be
too small for anyone to notice. Premature optimization is the root of
all evil!

Frank
Jun 27 '08 #5
On Jun 6, 8:06 pm, Sourabh Daptardar <saurabh.daptar...@gmail.com>
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.
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.
The lifetime of a class object may extend beyond the end of a
function. Where is the compiler to put the variable then?

More generally, register is no-op in almost all compilers
anyway. This was already the case when C++ was being
standardized; the keyword register is really only present for
reasons of backward compatibility with older C.
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.
Normally, if optimization is used, the compiler will keep
whatever variables are most used in a block of code in
registers, independantly of any keywords.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #6
On Jun 7, 12:43 am, Frank Birbacher <bloodymir.c...@gmx.netwrote:
Victor Bazarov schrieb:
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.
[snip]
But doesn't any
modern compiler know already enough how to do its job to not need our
hints about what to place where?
Right. The compiler always copies data from memory into
registers. Especially for heavy use. There is no need to and
no gain from specifying "register". Not even for local
variables (anymore).
And if "register" would make a difference then this difference
would be too small for anyone to notice.
Any effect would likely be negative. At different places in the
function, the compiler will keep different variables in
registers (including globals or class members); if register were
effective, it would reduce the number of registers the compiler
had at its disposition to do this.
Premature optimization is the root of all evil!
Especially when it actually results in pessimization (which
seems to frequently be the case).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4885
by: ravi_shankar | last post by:
hi all. what's the advantage of prefixing a varible with "extern" storage class specifier other than its default initializion . you can mail to me : ravi_shankarprasad@rediffmail.com --...
1
2497
by: ravi_shankar | last post by:
I know java,but I am just beginner in C.I have some confusions regarding extern storage specifier and default storage class specifier for a variable when it has file scope that is ,when it is not...
14
7890
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
10
2050
by: Mike - EMAIL IGNORED | last post by:
In my POD class: class MyPodClass { public: MyPodClass(MyCtorArgs); ... private: short data1; short data2;
9
1874
by: olanglois | last post by:
Hi, I am not sure if I have found a compiler bug (I am using VC++.NET2003) or if this is the correct behavior defined by the language but I am sure someone can clear up my confusion. Suppose the...
2
3257
by: sarathy | last post by:
Hi, What is the difference b/w a "storage class" and "storage class specifier"? It is said that there, Storage Class --automatic static ( K&R ) Storage Class Specifier --auto extern register...
1
3571
by: sunny | last post by:
Hi C Ref Man says " The typedef specifier does not reserve storage and is called a storage class specifier only for syntactic convenience " does this mean storage specifier for "user...
6
2248
by: fcvcnet | last post by:
Hi, I read the book C++ Primer, Fourth Edition By Stanley B. Lippman, Jos¨¦e Lajoie, Barbara E. Moo "If we define a class using the class keyword, then any members defined before the first...
15
7839
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
7125
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.