Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: Literal strings in C Message-ID: <8163@utzoo.UUCP> Date: Thu, 18-Jun-87 12:25:32 EDT Article-I.D.: utzoo.8163 Posted: Thu Jun 18 12:25:32 1987 Date-Received: Thu, 18-Jun-87 12:25:32 EDT References: <212@inco.UUCP>, <21065@sun.uucp> Organization: U of Toronto Zoology Lines: 18 Keywords: l-valued vs r-valued > It might be nice if C compilers were to offer an option that not only > attempted to put string literals in a non-writable portion of the > address space, but assigned them type "const char []", so that > attempts to modify them will be caught at compile time... A sensible idea at first glance, and in fact at least one earlier draft of X3J11 tried that. The trouble is that making this work consistently is hard: people routinely assign the addresses of string literals to "char *" pointers, so complaining about unconsting (to coin a word... ugh) will produce a zillion complaints unless one is, somehow, very selective about it. As I recall, the situation now is that unconsting, except by explicit cast, is illegal, which makes it impractical to make string literals const. Actually, I suspect that "egrep mktemp" will pick up the vast majority of the problem cases. -- "There is only one spacefaring Henry Spencer @ U of Toronto Zoology nation on Earth today, comrade." {allegra,ihnp4,decvax,pyramid}!utzoo!henry