Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: gnuarm question

2006-02-11 by Guillermo Prandi

Hi, Sean. From tests I did with GCC 4.0.1, I came into the conclusion 
that:

char* test1 = "TEST1"; <--- doesn't get copied to RAM
char  test2[] = {'T','E','S','T','2'}; <--- does get copied to RAM.

i.e., omiting the const modifier is not enough to make strings be 
copied to RAM. Strings declared with double quotes are considered 
const whether we say so or not. There are options to explore besides 
this. For instance, you can specify the section where you want your 
variable placed (.text, .data, etc.); I did no tests with that.

Guille

--- In lpc2000@yahoogroups.com, Sean <embeddedrelated@...> wrote:
>
> 
> Strings literals are stored in flash and copied into RAM as part of 
the 
> startup of the application (along with all other preinitialized 
> variables).  However to be safe it's better to explicitly declare 
anything 
> you want to be in flash as const.
> 
> If you didn't declare the array that you were using for is_any as a 
const 
> then the string data would be copied from flash to ram at startup.  
If it 
> is declared as const then it stays in flash and is referenced 
directly from 
> there without a ram counterpart.
> 
> -- Sean
> 
> At 20:46 2/10/2006, you wrote:
> >Sean,
> >
> >Thanks.  Does this mean the compiler does not 'move' strings like 
this
> >into ram?  So, I need not worry about the 'const' label?
> >I have a huge font array that I want in flash of course.
> >
> >TIA
> >
> >Glen
> >
> >
> >Sean wrote:
> > > test.c:32: warning: passing arg 1 of `is_any' discards 
qualifiers from
> > > pointer target type
> > >
> > > this is because you're passing a "const uchar *" as a "uchar *"
> > > param.  Changing either the function to is_any(const unsigned 
char
> > > *,char)  or removing const from the string declaration removes 
this
> > > warning, but it's only a warning, it won't effect the execution.
> > >
> > > -- Sean
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.