Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!uunet!mcsun!hp4nl!orcenl!bengsig From: bengsig@oracle.nl (Bjorn Engsig) Newsgroups: comp.lang.c Subject: Re: Initializing arrays of char Message-ID: <1009@nlsun1.oracle.nl> Date: 8 Oct 90 15:06:24 GMT References: <1990Oct4.152756.6850@micrognosis.co.uk> <15674@csli.Stanford.EDU> <26860@mimsy.umd.edu> Reply-To: bengsig@oracle.nl (Bjorn Engsig) Organization: Oracle Europe, The Netherlands Lines: 24 Article <26860@mimsy.umd.edu> by chris@mimsy.umd.edu (Chris Torek) says: | | In Classic (K&R-1) C, a |double-quoted string in an initializer context%, when setting the |initial value of a character array, was treated uniformly as if it were |a bracketed initializer consisting of all the characters, including |the terminating NUL, in the string. Yes, it seems to me that K&R1 says so - even if I would say it didn't. The rationale for ANSI C says that accepting 'char x[2] = "ab"' (omitting the NUL) is due to widely existing practice. This is in fact true, at least I have seen many Classic C compilers that allowed it and didn't warn about it. Since K&R1 seems to be clear, how come the compilers accepted it? Or does K&R1 actually hide it somewhere? As a comment to another note in this thread that string functions shouldn't be used with non NUL terminated strings; strncpy is actually designed to work with non NUL terminated fixed length strings, and you will normally use 'x[0]=0; strncat(x,s,n)' if you want a limited NUL terminated copy of strings, whereas 'strncpy(x,s,n)' may yield surprises. -- Bjorn Engsig, E-mail: bengsig@oracle.com, bengsig@oracle.nl ORACLE Corporation From IBM: auschs!ibmaus!cs.utexas.edu!uunet!oracle!bengsig "Stepping in others footsteps, doesn't bring you ahead"