Arm Community
Site
Search
User
Site
Search
User
Support forums
Arm Development Studio forum
Can a member variable be declared const in a class without initialization?
Jump...
Cancel
Locked
Locked
Replies
5 replies
Subscribers
119 subscribers
Views
4147 views
Users
0 members are here
Options
Share
More actions
Cancel
Related
How was your experience today?
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion
Can a member variable be declared const in a class without initialization?
SteveL SteveL
over 12 years ago
Note: This was originally posted on 5th January 2010 at
http://forums.arm.com
I am trying to define a class providing an interface to hardware registers. Some of the registers are read-only. I would like to declare these registers const so they cannot be written, but the compiler is insisting I initialize them. But by initializing them, it is guranteed they will be written.
Does anyone have a solution to this dilemma?
Thanks.
Sincerely,
Steve.
Parents
SteveL SteveL
over 12 years ago
Note: This was originally posted on 5th January 2010 at
http://forums.arm.com
Thanks for the input.
The codebase I am working with uses C++ extensively. It uses the linker to locate the object instantiated from the hardware registers class.
Here is an example:
(in registers.h file)
class c_Registers
{
public:
UINT32 GetRegister3() { return rw_register_3; }
SetRegister3(UINT32 value) { rw_register_3 = value; }
UINT32 GetRegister4() { return ro_register_3; }
private:
UINT32 rw_register_1;
UINT32 rw_register_2;
UINT32 rw_register_3;
UINT32 const ro_register_4;
UINT32 const ro_register_5;
};
(in registers.cpp file)
#pragma arm section zidata = "REG"
class c_Registers Registers;
(in scatter load file)
HW_REGISTERS_HDSECT 0xA000000 UNINIT
{
registers.o (REG)
}
What I want to do is be able to declare read only registers, ro_register_4 and ro_register_5, as const to protect against anyone adding code that would write the registers.
Unfortunately, the compiler wants me to initialize the const variables.
Thanks for your help.
Sincerely,
Steve.
Cancel
Vote up
0
Vote down
Cancel
Reply
SteveL SteveL
over 12 years ago
Note: This was originally posted on 5th January 2010 at
http://forums.arm.com
Thanks for the input.
The codebase I am working with uses C++ extensively. It uses the linker to locate the object instantiated from the hardware registers class.
Here is an example:
(in registers.h file)
class c_Registers
{
public:
UINT32 GetRegister3() { return rw_register_3; }
SetRegister3(UINT32 value) { rw_register_3 = value; }
UINT32 GetRegister4() { return ro_register_3; }
private:
UINT32 rw_register_1;
UINT32 rw_register_2;
UINT32 rw_register_3;
UINT32 const ro_register_4;
UINT32 const ro_register_5;
};
(in registers.cpp file)
#pragma arm section zidata = "REG"
class c_Registers Registers;
(in scatter load file)
HW_REGISTERS_HDSECT 0xA000000 UNINIT
{
registers.o (REG)
}
What I want to do is be able to declare read only registers, ro_register_4 and ro_register_5, as const to protect against anyone adding code that would write the registers.
Unfortunately, the compiler wants me to initialize the const variables.
Thanks for your help.
Sincerely,
Steve.
Cancel
Vote up
0
Vote down
Cancel
Children
No data