Yahoo Groups archive

Lpc2000

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

Message

Re: Problems with sting constants and gcc -On

2005-10-18 by Guillermo Prandi

I'm sure I've seen a flag somewhere in gcc to enable/disable the 
const-ization of string literals, but I can't find it right now.

Guille

--- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> 
wrote:
>
> At 09:08 PM 10/18/05 +0000, Guillermo Prandi wrote:
> >Actually:
> >
> >char *f = "Hello";
> >
> >Left "Hello" in the ROM area. Whilst:
> >
> >char f[] = "Hello";
> >
> >Left "Hello" in the RAM area (after copying from ROM, of course).
> >
> >Guille
> 
> I rather suspect that's an allowed interpretation of the standard 
> then.  GCC is quite good about that.  It certainly follows the 
practice of 
> some UNIX compilers.  Unfortunately that's a non-obvious type pun.
> 
> Thankfully lint (PC-Lint) catches it (although as a C++, not a C 
error, 
> Makes sense; AIUI the type of a string literal is different in the 
two 
> languages.)
> 
> char *f = "test";
> e:\cygwin\home\radsett\newlib-lpc\test11.c  33  Info 1776: 
Converting a string
>      literal to char * is not const safe (initialization)
> 
> Thanks, another hole in my knowledge corrected.
> 
> 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.