Subject: Re: mktemp core dumps
To: None <netbsd-help@NetBSD.ORG>
From: Peter Seebach <seebs@solon.com>
List: netbsd-help
Date: 12/28/1996 09:52:26
>One more question, just out of curiosity: Obviously gcc places the
>string in the code segment, which is per default 'const'. mktemp() on
>the other hand is not defined to treat the buffer as const, for
>obvious reasons, so shouldn't gcc complain?

No.

The type of a string literal is "char *", *NOT* "const char *".  This is
necessary for historical reasons; thousands of programs contain code
like
	char *tmp = "unassigned string";
or perhaps even using useful values.

To get a warning, use -Wwrite-strings, to make the invalid code run,
use -fwriteable-strings.  ANSI says the code is broken, so I suggest not
using the latter.

The former is also incorrect, by ANSI, because we were fairly unambiguous
about the non-const-qualified nature of string "constants".

The problem with making them "const char *" can be made clear by the
task of attempting to write strchr() correctly in C; it can't be done.
You *have* to "cast away const".  This is a sign that there's something
wrong with the semantics of const... Me, I avoid it like the plague.

-s