Newsgroups: comp.lang.c Path: utzoo!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: Initializing arrays of char Message-ID: <1990Oct7.194740.23349@sq.sq.com> Organization: SoftQuad Inc., Toronto, Canada References: <9418:Oct503:06:2790@kramden.acf.nyu.edu> <3568@dftsrv.gsfc.nasa.gov> <21242:Oct604:56:1390@kramden.acf.nyu.edu> Date: Sun, 7 Oct 90 19:47:40 GMT Lines: 30 > Again, the right way (as a point of style, he means) > to initialize a five-element character array is to > list the five characters explicitly: > char baz[5] = { '1', '2', '3', '4', '5' } ; > If you use "12345", you'll confuse the reader (not to mention any old > compilers) into thinking that you really want a (0-terminated) string. This may be true if you're dealing with 5-character arrays, but it fails as soon as there are too many initializers to count by eye. Suppose it was: char parity[64] = "EOOEOEEOOEEOEOOEOEEOEOOEEOOEOEEOOEEOEOOEEOOEOEEOEOOEOEEOOEEOEOOE"; It's obvious from its content that this is not a string to be printed, so the absence of a trailing null* should not cause confusion. You could add a one-line comment if you you really must. But I would (mildly) prefer to see the one line above than four lines of 'E', 'O', 'O', 'E', 'O', ... *or NUL, or '\0', but, please, never NULL. -- Mark Brader "Metal urgy. The urge to use metals. SoftQuad Inc., Toronto That was humans, all right." utzoo!sq!msb, msb@sq.com -- Terry Pratchett: Truckers This article is in the public domain.