Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!samsung!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <1990Oct05.191543.29538@virtech.uucp> Date: 5 Oct 90 19:15:43 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> <15674@csli.Stanford.EDU> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 30 In article <15674@csli.Stanford.EDU> poser@csli.stanford.edu (Bill Poser) writes: >This means that the assignment of "12345" to an array of five characters, >is legal. If K&R2 here reflects the standard, then both initializations >are legitimate. While it is "legal" it still should get a warning since it is doing something that you may not expect. >This seems to me to be a bad idea. Everywhere else, one has to take >into account the terminating null. For example, x[5] = 'a' is >an error. Not counting the terminating null here is inconsistent. This has nothing to do with a terminating null. x[5] is illegal because you are accessing an element beyound the end of the array (assuming it was declared as char x[5]). >Can anyone explain this decision? Probably because that was the existing standard (the way C has worked all along). Another way to look at this is that "char x[dim];" declares an array of characters, not a character string. So the null need not be there and without this rule you couldn't initialize the last element of the array to be a non-null. -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170