Xref: utzoo comp.lang.c:11766 comp.std.c:258 Path: utzoo!attcan!uunet!husc6!spdcc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c,comp.std.c Subject: should string literals be const? (was: `static') Message-ID: <5900@haddock.ISC.COM> Date: 8 Aug 88 18:53:30 GMT References: <644@m10ux.UUCP> <503@draken.nada.kth.se> <12840@mimsy.UUCP> <255@quintus.UUCP> <12891@mimsy.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Followup-To: comp.std.c Organization: Interactive Systems, Boston Lines: 18 In article <12891@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Strangely, while "string"s are allowed to be read-only, they have type `array >of char' rather than `array of const char'. (I think this is a mistake.) It would certainly be more consistent. As Dennis Ritchie said, having two non-writable widgets (string literals and consts) without making the former a case of the latter indicates that something was botched. The Committee says that it's to allow old code of the form `char *p = "foo";' to be grandfathered in without generating a diagnostic for assigning a const to a non-const. I'm not completely convinced by this argument. If p is being used in a non-const context, then there *should* be a diagnostic. If not, then it should logically be declared const, and programmers should be encouraged to do so (a warning may be appropriate here). At the very least, X3J11 should have deprecated non-const string literals. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint Followups to comp.std.c.