Initializing arrays of char
Neil Readwin
nreadwin at micrognosis.co.uk
Fri Oct 5 01:27:56 AEST 1990
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 at micrognosis.co.uk
W Westfield: Abstractions of hammers aren't very good at hitting real nails
More information about the Comp.lang.c
mailing list