EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Using Hantronix Chip on glass technology LCD Modules

Started by wickedmonster2002 May 24, 2006
Richard,

Can you explain why you think removing "const" gives the code
a "better chance"?

Regardless of whether the code is running from flash or RAM, if you
leave out const in a declaration, you will be using up RAM, which if
you have a lot of constant data is probably not a good idea. In
general:

const int foo = 23;

will be placed in a read-only section of memory (i.e. flash if built
for flash), whereas:

int foo = 23;

will be placed in a read/write section (i.e. RAM) even if the code
is built for flash. The initialiser value is also placed in a read-
only section and is copied in as part of the 'C' run-time
initialisation.

You can override this behaviour by playing with compiler and/or
linker options, but why bother when "const" does it for you?

Or am I misreading what you're suggesting?

Brendan

--- In l..., newmanrf@... wrote:
>
>
> > Question: Why get rid of const? I would have thought you would
still
> > want this
> > in flash.
> >
>
> Robert,
>
> Yes your right. But for now it wont hurt him to remove it as
if he is
> building for flash its there and if he is building for ram its
still
> there. The idea is to get the code working first and removing that
> gives him a better chance... as long as he does not run out of ram
if
> he is compiling to run out of ram. So for all of us that knows
what it
> does and why leave it. If it looks funky to you comment it out. You
> will know that you need it eventually.
>
> Richard Newman
> Pittsburgh PA USA
>





An Engineer's Guide to the LPC2100 Series


The 2024 Embedded Online Conference