VMS pointer problems continue.

Chris Torek chris at mimsy.UUCP
Sat Mar 26 05:04:21 AEST 1988


In article <1494 at se-sd.sandiego.NCR.COM> rns at se-sd.sandiego.NCR.COM
(Rick Schubert) writes:
>Although Richard A. O'Keefe has pointed out the primary error in [

	char *wr(a) int a; { char b = "Arf!"; return (b); }
	/* should be	     char *b = ... */
	/* (this error should cause at least a warning at compile time) */

>] ... there is another error, although most implementations of C
>will handle it in the intended way (notice that I did not say "the
>right way").  The string pointed to by b ("Arf!") should be considered
>local to wr(); the compiler is free to allocate it on the stack . . . .

This is not the case.  String constants have type `array N of char'
and static storage duration.  These are the only anonymous aggregate
types that exist in C.  Writing

	char *wr() { return ("Arf!"); }

is essentially equivlaent to writing

	char *wr() {
		static char _not_named_[5] = { 'A', 'r', 'f', '!', '\0' };
		return (_not_named_);
	}

>I submitted the above, but inews asked for more; rather than just filling
>the required space, I'll try to make efficient use of it by giving
>one example of <<interesting>> behavior.  [deleted]

Well, at least *someone* had the sense to fill with something other than
`filler' lines.  You can also change the quote character to something other
than `>'.  E.g., in vi, type

	:%s/^>/-/
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list