Initializing arrays of char

John Bickers jbickers at templar.actrix.co.nz
Sat Oct 6 04:55:00 AEST 1990


Quoted from - poser at csli.Stanford.EDU (Bill Poser):
> 	...the number of characters in the string, NOT COUNTING
> 	THE TERMINATING NULL CHARACTER, must not exceed the
> 	size of the array. [emphasis mine]

> an error. Not counting the terminating null here is inconsistent.
> Can anyone explain this decision?

    Sounds like this is intended to allow a nice way to initialize
    character arrays that aren't necessarily strings.

    Like, say, a 4 character ID in a structure, that is meant to be
    compared and writ with things like mem... or strn...

    Consider that a character array is not necessarily going to be used as
    a "string", and since C doesn't distinguish between the two with any
    sort of type keyword, it's better to provide for the more general case.

    Does lint warn about this sort of thing?
--
*** John Bickers, TAP, NZAmigaUG.         jbickers at templar.actrix.co.nz ***
***          "All I can do now is wait for the noise." - Numan          ***



More information about the Comp.lang.c mailing list