Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!lll-tis!mordor!sri-spam!robert From: robert@sri-spam.istc.sri.com (Robert Allen) Newsgroups: comp.lang.c Subject: Buffer referencing between functions. Message-ID: <10756@sri-spam.istc.sri.com> Date: Mon, 19-Oct-87 17:32:02 EDT Article-I.D.: sri-spam.10756 Posted: Mon Oct 19 17:32:02 1987 Date-Received: Tue, 20-Oct-87 22:44:17 EDT Organization: SRI International, Menlo Park, CA Lines: 65 Keywords: *(auto_variables) in calling functions? Pardon me if this question seems naive, but I've been thinking about it and need some authoritative answers. Below is a code fragment to illustrate my problem; struct stack_vars { char *frombuf; int frombuf_index; /* 0-2000 */ char *tobuf; int frombuf_index; /* 0-2000 */ } void calling(inbuf,inbuf_index) char inbuf[]; int inbuf_index; { struct stack_vars data; char dbuf[2000]; data.frombuf = inbuf; data.frombuf_index = inbuf_index; data.tobuf = dbuf; data.tobuf_index = 0; called(&data); } void called(sv) struct stack_vars *sv; { /* do some buffer processing */ bcopy(sv->frombuf,sv->tobuf,sv->frombuf_index); sv->tobuf_index = sv->frombuf_index; } In the example above "called()" depends on the fact that the pointer passed to the automatic variable 'dbuf' in "calling()" is correct. Based on my experience the above code fragement should work, since the stuff is passed on the stack and the calling routine is not "temporarily deallocated". My question is, is it technically correct to reference an 'external' variable via a pointer in this manner? If the allocated space in dbuf were global to the file or the program I wouldn't be suspicious, but since it is an automatic variable in a calling function I'm a bit concerned with the correctness of it. Email or posting of information will be greatly appreciated. -- --------------------------------------------------------- Robert Allen, robert@spam.istc.sri.com 415-859-2143 (work phone, days) ---------------------------------------------------------