Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!wuarchive!decwrl!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <5658@stpstn.UUCP> Date: 8 Oct 90 15:16:38 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> <15674@csli.Stanford.EDU> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 28 In article <15674@csli.Stanford.EDU> poser@csli.stanford.edu (Bill Poser) writes: ->Regarding the assignment of "12345" to char x[5] and struct{char x[5]}, ->I spoke too soon. K&R2 contains a detail I hadn't noticed, and am not ->sure that I approve of. On p.219, in the discussion of initialization ->of fixed size arrays by string constants, it states: -> -> ...the number of characters in the string, NOT COUNTING -> THE TERMINATING NULL CHARACTER, must not exceed the -> size of the array. [emphasis mine] -> ->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. -> ->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. ->Can anyone explain this decision? I can't explain the decision, but I can understand that it might be useful. It does make sense to have an array of characters in the same sense that one has an array of integers. In that case, if one knows the length, there should be no requirement that a character with the value 0 be stored to signify the end. It does seem to be an opportunity for error, though. Ken