Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpda!hpcuhb!hpcllla!hpclisp!defaria@hpclapd.HP.COM From: defaria@hpclapd.HP.COM (Andy DeFaria) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <660085@hpclapd.HP.COM> Date: 5 Oct 90 16:49:29 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> Organization: Hewlett-Packard Calif. Language Lab Lines: 26 >/ hpclapd:comp.lang.c / poser@csli.Stanford.EDU (Bill Poser) / 6:16 pm Oct 4, 1990 / >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? >---------- It seems to me (and I am be no stretch of the imagination a C expert) that K&R C is saying "Sure you can use all 5 characters for a legitimate string. You can manipulate them any way you want. You might be using it to contain a fixed length string of 5 characters. But don't you ever try to use it with any string procedures (strlen, or even printf's %s operator) or expect to get burned!"