Initializing arrays of char

Bjorn Engsig bengsig at oracle.nl
Fri Oct 5 18:57:19 AEST 1990


re:  char mesg[5] = "help!"; /* what about the null terminator? */

The ANSI standard says (3.5.7):

"Successive characters of the character string literal (including the 
terminating null character if there is room or if the array is of unknown size)
initialize the elements of the array."

and the rationale mentions:

"(Some widely used implementations provide precedent.)"

further, it fits well with the way strncpy() works.
-- 
Bjorn Engsig,	Domain:		bengsig at oracle.nl, bengsig at oracle.com
		Path:		uunet!mcsun!orcenl!bengsig
		From IBM:	auschs!ibmaus!cs.utexas.edu!uunet!oracle!bengsig



More information about the Comp.lang.c mailing list