Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: String help! Message-ID: <573@rlgvax.UUCP> Date: Wed, 13-Mar-85 03:19:41 EST Article-I.D.: rlgvax.573 Posted: Wed Mar 13 03:19:41 1985 Date-Received: Thu, 14-Mar-85 05:28:10 EST References: <1156@ukma.UUCP> <113@mit-athena.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 35 > Hmmm... According to some of the advice here, the following is not > an acceptable way to declare an initialized array: > > char *fup = "0123456789"; Damn straight. It defines an initialized *pointer* which points to a nameless array. Try char fup[] = "0123456789"; to declare an array. This *is* the sensible thing to do. If you actually plan to *modify* that array, the first example is truly lousy; if you end up putting 11 characters into it, you stomp on some strange area of memory (unless the string is put in read-only memory, in which case your program gets properly punished). If you expect up to 128 characters in the array, try char fup[128+1/*for the null terminator*/] = "0123456789"; Why should random strings get put in writable areas of your address space? Currently, there are a lot of horrible kludges to move strings, etc. into read-only sharable text space; putting strings there by default obviates the need for some of those kludges (the "const" attribute obviates the need for the others). Please learn how to construct initialized strings before blindly criticizing this language change. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy -- Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy