Is this ok??

Art Neilson art at pilikia.pegasus.com
Sun Mar 10 14:04:29 AEST 1991


In article <1991Mar9.073231.1364 at athena.mit.edu> scs at adam.mit.edu writes:
>In article <1991Mar08.191107.23161 at pilikia.pegasus.com> art at pilikia.pegasus.com (Art Neilson) writes:
>>In article <DAVIS.91Mar6213546 at pacific.mps.ohio-state.edu> davis at pacific.mps.ohio-state.edu  (John E. Davis) writes:
>The code posted by John Davis was correct, although it contained
>several (perfectly legal) pointers to pointers which apparently
>confused both a VMS compiler (thus John's original question) and
>Arthur Neilson (thus these irrelevant criticisms).  The code
>passes lint -hbxa with flying colors (i.e. no complaints about
>argument mismatches) and runs correctly under any number of
>compilers.

Guess I deserve a bit of public chastisement for my criticisms.
I still don't get why the string assignment

	*s = "Hello\n";

in fm2() is ok.  Raymond Chen sent me an email stating that storage for
"Hello\n" was allocated as static anonymous readonly by the compiler.
I had always thought that the rvalue in a pointer assignment had to be an
address.  The usual way I do assignments of this nature is to either
explicitly declare an array large enough to hold the string or malloc
the storage and move the data there, or assign the pointer globally
(outside of main) like:

char *s = "Hello\n";	/* aggregate initializations out here */

main()
{

John's program does compile and run on my system ;^) (sheepish grin) 
so it must be ok.  Since the assignment is ok, how large a string can be
assigned in this manner ?  Does the constant go in .data or .bss ??
-- 
Arthur W. Neilson III		| INET: art at pilikia.pegasus.com
Bank of Hawaii Tech Support	| UUCP: uunet!ucsd!nosc!pilikia!art



More information about the Comp.lang.c mailing list