Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!decwrl!shelby!csli!poser From: poser@csli.Stanford.EDU (Bill Poser) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <15674@csli.Stanford.EDU> Date: 5 Oct 90 01:16:07 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> Reply-To: poser@csli.stanford.edu (Bill Poser) Organization: Center for the Study of Language and Information, Stanford U. Lines: 17 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?