String help!

Bill Richard wjr at x.UUCP
Thu Mar 14 09:34:00 AEST 1985


> Hmmm... According to some of the advice here, the following is not
> an acceptable way to declare an initialized array:
> 
> 	char *fup = "0123456789";
> 
> The reason is that some C compilers are likely to take the string 
> constant and put it into a read-only portion of memory.  Instead,
> if we want an initialized character array, we are supposed to say 
> something like:
>
> <2 examples of run time array initialization>
>
> To this, I say "NONSENSE".  Any compiler-writer that considers a
> string constant to be read-only is a total and utter turkey, and
> I would rather use a sensible compiler.  ...
> 			John Chambers

	To this I say "RTFM John". K&R Section 8.6 (pg 199) says:
"A final abbreviation <of initializer forms> allows a _char_ array to
be initialized by a string. In this case successive characters of the
string initialize the members of the array." Thus:

 	char fup[] = "0123456789";

will give you a writable array of chars initialized to look like the
string. I assume that the ANSII committee hasn't broken this feature,
if they have I have a complaint.

	Or are you making a general objection to constants being
constant? In which case you must love those Fortran compilers which
allow you to dynamically change the value of a NUMERIC constant. :-)

-- 
----
William J. Richard @ Charles River Data Systems
983 Concord St. Framingham, MA 01701
Tel: (617) 626-1112
uucp: ...!decvax!frog!wjr



More information about the Comp.lang.c mailing list