# Simple question

This topic is 4924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How can a bitwise constant be placed in ROM? THX!

##### Share on other sites
Fist: What is bitwise constant? There are bitwise operators and constants...

Second: It's only operating system's good will to place something in ROM. However - if it sees some good candidate for being in ROM, there's a change it will be placed in ROM.

Oxyd

##### Share on other sites
Why should it matter where it's at?

##### Share on other sites
Yeah, there's something a bit weird about wanting to put bitwise constants in ROM. Are you wanting it in ROM to write protect it? Because if you are, most languages provide constant variables that you can't write to after you set them (well, you can, but it's a complete hack).

You'll need to give a bit more detail if you want to get some help here.

-Auron

##### Share on other sites
Wait, you can't write to ROM, can you? Unless he's talking about a CD rom.

##### Share on other sites
Simple question alright. So simple nobody has a freakin clue what the hell you are talking about!
Start from the absolute beginning. What are you writing?

##### Share on other sites
Quote:
 Original post by Kelly GWait, you can't write to ROM, can you? Unless he's talking about a CD rom.

Well, you can, kind of... but I HIGHLY doubt that he's getting at anything like erasing the OS from the ROM on a console or something.

Then again...

-Auron

##### Share on other sites
Sorry ,i was out for a while,this is what i've found in a book
ROMability
If an object is defined as const, it is a candidate to be placed in read-only memory (ROM), which is often an important consideration in embedded systems programming. Simply making an object const, however, is not enough – the requirements for ROMability are much stricter. Of course, the object must be bitwise-const, rather than logical-const. This is easy to see if logical constness is implemented only through the mutable keyword, but probably not detectable by the compiler if constness is cast away inside a const member function. In addition,

The class or struct must have no user-defined constructors or destructor.
There can be no base classes (covered in Chapter 14) or member objects with user-defined constructors or destructors.
The effect of a write operation on any part of a const object of a ROMable type is undefined. Although a suitably formed object may be placed in ROM, no objects are ever required to be placed in ROM.

It should be more clear now!

##### Share on other sites
Guys i know this is sick but i really want an answer the excerpt i gave you seems strange indeed.[lol]

##### Share on other sites
Quote:
 Original post by DaosSorry ,i was out for a while,this is what i've found in a bookROMabilityIf an object is defined as const, it is a candidate to be placed in read-only memory (ROM), which is often an important consideration in embedded systems programming. Simply making an ...a ROMable type is undefined. Although a suitably formed object may be placed in ROM, no objects are ever required to be placed in ROM.It should be more clear now!

If you're working with embedded systems, sure, place the constant within the E(E)PROM memory, why waste good (often limited in embedded systems) RAM on something that is already defined? As for specifically a bit-wise constant, unless you're talking about a flag bit (in a bitmap arrangement with other flags) you could, but you'd waste the other 7 bits within that space...

>shrug<

Is this for an embedded project?

##### Share on other sites
Not really or i don't know i was just curios!I'm not a native English speaker so i don't have any slim clue about "embeded systems "my Webster dictionary does'n give me any idea[lol]and this is where the confusion comes from.
Thx!

##### Share on other sites
Embedded systems are systems where the operating system is embedded into a ROM chip on the hardware. Pretty much any computer that isn't a desktop or notebook is going to be an embedded system. This means most PDAs, cell phones, consoles (like the PS2 or Gameboy) and so on.

I can't say as I understand their little spiel about bitwise versus logical const either, and English is my first language, so don't feel bad.

But it seems to be saying that if you want to ensure that certain constant data is going to be placed in ROM, you're going to have to do a bit more than put "const" in front of it.

-Auron

##### Share on other sites
C++ on embedded systems? is nothing sacred? but seriously, const was designed for addressing the problems with C's #define statement. one of the fixes involves actually allocating memory (RAM) for the constant. i would think that most compilers would allocate for const everytime, but if they are for embedded systems some may support a compiled const. since this is just for your curiosity and learning, i wouldn't worry too much about this, and Read The Manual for your compiler when it becomes important. other than that #define will never allocate memory and should work fine.

##### Share on other sites
Quote:
 Original post by anist[snip/]but seriously, const was designed for addressing the problems with C's #define statement.

Correction: #define is not a C statement - it's a pre-processor directive and thus not part of the C language.
Quote:
 one of the fixes involves actually allocating memory (RAM) for the constant.

Pardon?
const is a language construct (type-qualifier) that provides a semantic for expressing a constant (read: non-modifiable piece of information). period. Whether this information is allocated in RAM or ROM is context sensitive and thus up to the compiler.
E.g.
const int answer = 42;
will never allocate RAM, it's basically the same as
#define answer 4
Quote:
 i would think that most compilers would allocate for const everytime, but if they are for embedded systems some may support a compiled const.