Yahoo Groups archive

Lpc2000

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

Message

Re: [lpc2000] Problems with sting constants and gcc -On

2005-10-17 by Robert Adsett

At 11:08 PM 10/17/05 +0000, Guillermo Prandi wrote:
>Hi! Has anybody found this? I'm using gcc 4.01 (latest WinARM) and I'm
>compiling for LPC2138 (ARM7). If I use this kind of stuff, constants
>don't get to the HEX file:

It sounds like a problem with your startup code.


>char *c = "Hello";


This string, for instance needs to be copied to RAM since your declaration 
indicates it's modifiable.


>or
>
>my_func("Hello");


As will this if my_func is prototyped as void my_func (char *)
I think that's the case.


>However, if I use a built-in function like printf or puts, they do!:
>
>printf("Hello");


This however can point to the string in flash since printf expects a const 
string.

The prototype is something like

int printf( const char *, ...);


Question:  Does the problem disappear if you declare the first case as

const char *c = "Hello";

and prototype the function in the second as

void my_func( const char *);




>This only happens with -On, where n != 0.


I'd be really confident that was the problem, except I don't see how this 
final statement fits in.

Still the const/non-const nature of the two cases cries out as being 
critical.  Maybe you are writing over the strings in RAM?

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

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.