Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site x.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!cybvax0!frog!x!wjr From: wjr@x.UUCP (Bill Richard) Newsgroups: net.lang.c Subject: Re: String help! Message-ID: <431@x.UUCP> Date: Wed, 13-Mar-85 18:34:00 EST Article-I.D.: x.431 Posted: Wed Mar 13 18:34:00 1985 Date-Received: Fri, 15-Mar-85 02:07:08 EST References: <1156@ukma.UUCP> <113@mit-athena.UUCP> Organization: Charles River Data Systems, Framingham MA Lines: 38 > Hmmm... According to some of the advice here, the following is not > an acceptable way to declare an initialized array: > > char *fup = "0123456789"; > > The reason is that some C compilers are likely to take the string > constant and put it into a read-only portion of memory. Instead, > if we want an initialized character array, we are supposed to say > something like: > > <2 examples of run time array initialization> > > To this, I say "NONSENSE". Any compiler-writer that considers a > string constant to be read-only is a total and utter turkey, and > I would rather use a sensible compiler. ... > John Chambers To this I say "RTFM John". K&R Section 8.6 (pg 199) says: "A final abbreviation allows a _char_ array to be initialized by a string. In this case successive characters of the string initialize the members of the array." Thus: char fup[] = "0123456789"; will give you a writable array of chars initialized to look like the string. I assume that the ANSII committee hasn't broken this feature, if they have I have a complaint. Or are you making a general objection to constants being constant? In which case you must love those Fortran compilers which allow you to dynamically change the value of a NUMERIC constant. :-) -- ---- William J. Richard @ Charles River Data Systems 983 Concord St. Framingham, MA 01701 Tel: (617) 626-1112 uucp: ...!decvax!frog!wjr