From: hartman@ulogic.UUCP (Richard M. Hartman)
Newsgroups: comp.lang.c
Subject: Re: Strings and integer sizes
Date: 14 Oct 92 19:22:51 GMT
Organization: negligable

In article <1992Oct13.154448.13355@taumet.com> steve@taumet.com (Steve Clamage) writes:
>hartman@ulogic.UUCP (Richard M. Hartman) writes:
>
>>:I agree when you say that zoe[3]= "abc"; is an erroneous initializer
>>:when you want to store a _string_ in the array, but otherwise this
>>:is all perfectly legal. The ANSI-C standard even states this explicitely
>>:in paragraph 3.5.7 Initialization.
>
>>Unfortunately this is correct.  Stupid and misleading, but correct.
>
>>Another thing we can thank the standards committee for....
>
>According the Rationale in the ANSI C Standard, this was existing
>practice in some widely-used compilers.
>
>If X3J11 had made |zoe[3]="abc";| illegal, someone else would be saying,
>"Stupid and misleading, another thing we can thank the standards
>committee for ..."

Naah.  They'd be saying "Stupid and, damned annoying..."  I really
cannot see anyone honestly saying that |zoe[4] = "abc";| and 
|zoe[3] = { 'a', 'b', 'c' };| are misleading but |zoe[3] = "abc";|
isn't.  It might be annoying to have to use the long form, but NOT
misleading.			;)

>Two things I have learned in doing standards work:
>
>1.  Some people like to complain about a standard without reading it
>    to find out what it actually says.
>
>2.  No matter what you decide, some people will complain loudly about
>    how you have ruined the language.

Of course.

>The particular problem faced by X3J11 (the ANSI C Committee) was trying
>to reconcile mutually incompatible implementations of C, none of which
>violated K&R1.  No one decision could satisfy everyone.

But it does violate K&R1 (as far as I can determine).

p84:
	Character arrays are a special case of initialization; a string
	may be used instead of the braces and commas notation:

		char pattern[] = "the";

	This is a shorthand for the longer but equivalent

		char pattern[] = { 't', 'h', 'e', '\0' };

	When the size of an array of any type is ommitted, the compiler
	will compute the lenght by counting the initializers.  In this
	specific case, the size is 4 (three characters plus the 
	terminating \0).

This seems to establish that the size of the char array "the" is
clearly 4, and therefore should not be allowed as an initializer
for a char array of size 3.

This is (as far as I can tell) the only place in the book where
the size of a string constant is mentioned.

The char array initializations discussed in K&R1 all seem to
be of the '[]' type (size unspecified), so it is possible that
compilers that accepted this initializer did not violate K&R
_except_ for the fact that the size of a string constant is
clearly established on p84 (excerpted above).

I can understand the convenience argument (although I disagree
on the grounds that it is misleading as to the intended use of
the variable so initialized).  But I am not convinced that compliers
that accepted it (prior to the ANSI spec) were _not_ in violation
of K&R.

Am I missing something?

		-Richard Hartman
		hartman@ulogic.COM

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Nobody has ever had a sexual fantasy about being tied
 to a bed and ravished by somebody dressed as a liberal."    -P.J. O'Rourke