Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!stc!miclon!miclon!nreadwin From: nreadwin@micrognosis.co.uk (Neil Readwin) Newsgroups: comp.lang.c Subject: Initializing arrays of char Message-ID: <1990Oct4.152756.6850@micrognosis.co.uk> Date: 4 Oct 90 15:27:56 GMT Sender: news@micrognosis.co.uk (News account) Reply-To: nreadwin@micrognosis.co.uk (Neil Readwin) Organization: Micrognosis, London, UK Lines: 25 Can someone tell me why the following initializer is legal inside a structure, but not outside it ? Or is it a compiler bug ? struct foo { char x[5]; } bar = {"12345"}; char baz[5] = "12345"; The VMS compiler barfs on the second one with %CC-W-TRUNCSTRINIT, String initializer for "baz" contains too many characters to fit; truncated. At line number 5 in CASSIUS:[NREADWIN.TMP]ZZ.C;4. The SunOS compiler agrees "zz.c", line 5: too many initializers gcc seems quite happy with both. I was unable to decrypt what K&R had to say on the matter - should the null character appended to the string count as an initializer in both cases ? Disclaimer: 818 Phone: +44 71 528 8282 E-mail: nreadwin@micrognosis.co.uk W Westfield: Abstractions of hammers aren't very good at hitting real nails