Yahoo Groups archive

Lpc2000

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

Message

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

2005-10-19 by Robert Adsett

At 02:47 PM 10/19/05 +0000, bdmlpc wrote:
>sorry for this last remark, but it is not an interpretation of C
>standard.

What isn't?

>char* f1 = "Hello";


Oh, I do realize the difference between a pointer and an array.  After 
working with the language for a decade or two I should hope I do.

The only vague area in my mind was the use of a string literal to 
initialize a non-constant pointer.  A construct I don't think I've used on 
an ANSI/ISO compliant compiler.  I do recall C and C++ regarding string 
literal as different types largely to allow the above statement to be legal 
C so that historical source will still compile and execute.  The only 
question I had was whether the standard allowed the string literal to be 
const in that case (and it appears it does) in which case you get an 
implicit type punning where a non-const pointer points to a const area of 
memory.

Not very type safe.  I'd rather the construct was deprecated but I'm not 
going to hold my breath.  Maybe C99 is moving in that direction?  If so 
I've not heard that it is.

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.