Home

Pete Becker <pete@versatilecoding.com> writes:
[...]
> The reason is that historically, C-style strings were not always
> constant, and there was code that relied on this. The rule in C++ is
> that the type of a string literal is array-of-const-char. The literal
> can be converted into a pointer-to-char, but that you write to it at
> your peril. That preserves the status quo. The conversion is

There's a little more to the historical background than that. Early C
didn't have the 'const' keyword, so if you wanted to pass a string
literal to a function, that function had to take a 'char*' argument:

func(str)
char *str;
{
/* code that doesn't modify the string */
}

...

func("Hello, world");

If ANSI C had made string literals const, such code (which was
perfectly valid when it was written) would have been broken, and the
transition from pre-ANSI to ANSI would have been more difficult.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

previous
next

Running daemon with zdaemon ... example help?
Re: Pythonwin Install COM exceptions on Windows Vista Ultimate
Ask for general suggestion on project design.
Re: Check If Object Deleted
Re: list index()
reklamy łódź
Połączenie Warszawa - Kolonia
serwis wózków widłowych
vdc w polsce
tanie pozycjonowanie