From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 2 12:24:50 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3E80437B401 for ; Wed, 2 Jul 2003 12:24:50 -0700 (PDT) Received: from mail.mundomateo.com (24-56-193-117.mdmmi.voyager.net [24.56.193.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 359A843FAF for ; Wed, 2 Jul 2003 12:24:49 -0700 (PDT) (envelope-from matthew@mundomateo.com) Received: from www.mundomateo.com (localhost.mundomateo.com [127.0.0.1]) by mail.mundomateo.com (Postfix) with SMTP id 8005F5C91 for ; Wed, 2 Jul 2003 15:24:47 -0400 (EDT) Received: from 216.120.158.65 (SquirrelMail authenticated user matthew) by www.mundomateo.com with HTTP; Wed, 2 Jul 2003 15:24:48 -0400 (EDT) Message-ID: <1843.216.120.158.65.1057173888.squirrel@www.mundomateo.com> In-Reply-To: <66D4CD3C-ACB8-11D7-A6BB-00306544D642@mac.com> References: <1560.216.120.158.65.1057168456.squirrel@www.mundomateo.com> <66D4CD3C-ACB8-11D7-A6BB-00306544D642@mac.com> Date: Wed, 2 Jul 2003 15:24:48 -0400 (EDT) From: "Matthew Hagerty" To: freebsd-hackers@freebsd.org User-Agent: SquirrelMail/1.4.1 [CVS] MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal Subject: Re: Can a pass-by-reference var be assigned to a local var? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: matthew@mundomateo.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jul 2003 19:24:50 -0000 Justin, Yes, after reading your post, I found this: -- Structure Assignments ANSI C compilers allow the information in one structure to be assigned to another structure, as in: binfo=addr_info; -- I never knew that. I wonder why that functionality is done for structs, but not extended to arrays as well? Why make exceptions for structs like that? Thanks for clearing that up for me! Matthew > I think you're missing something. > > This is "structure assignment" in action. The variable 'sbp' is a > *statb, and the assignment assigns a structure, sb2, to *sbp, which is > itself a structure, not a pointer. > > Regards, > > Justin > > On Wednesday, July 2, 2003, at 10:54 AM, Matthew Hagerty wrote: > >> Greetings, >> >> I was looking over the code for the tail command and found something >> that >> seems wrong. Below is the abbreviated code that highlights my concern. >> Basically, sb is defined in main() and passed to forward() (and >> reverse()) >> by reference. Then in forward() sb2 is defined, and finally sb is set >> to >> sb2. >> >> Two things come to mind that don't seem right: 1. What happens to sb >> when >> forward() returns? It was pointing to sb2 which was a local var of >> forward()... and 2. The assignment *sbp = sb2 happens in a loop and >> could >> be executed more than once, which seems to make the comparisons just >> prior >> to the assignment usless 2 or more loop iterations. >> >> Am I missing something? It seems to me that instead of *sbp = sb2, it >> should be done with memcpy() or something? Any insight would be >> greatly >> appreciated. >> >> Thanks, >> Matthew >> >> >> In tail.c: >> >> int >> main(argc, argv) >> int argc; >> char *argv[]; >> { >> struct stat sb; >> . >> . >> if ((fp = fopen(fname, "r")) == NULL || >> fstat(fileno(fp), &sb)) { >> . >> . >> if (rflag) >> reverse(fp, style, off, &sb); >> else >> forward(fp, style, off, &sb); >> . >> . >> } >> >> Then in forward.c: >> >> void >> forward(fp, style, off, sbp) >> FILE *fp; >> enum STYLE style; >> off_t off; >> struct stat *sbp; >> { >> int ch, n, kq = -1; >> int action = USE_SLEEP; >> struct kevent ev[2]; >> struct stat sb2; >> struct timespec ts; >> . >> . >> if (Fflag && fileno(fp) != STDIN_FILENO) { >> while (stat(fname, &sb2) != 0) >> /* file was rotated, wait until it reappears */ >> (void)sleep(1); >> if (sb2.st_ino != sbp->st_ino || >> sb2.st_dev != sbp->st_dev || >> sb2.st_rdev != sbp->st_rdev || >> sb2.st_nlink == 0) { >> fp = freopen(fname, "r", fp); >> if (fp == NULL) { >> ierr(); >> return; >> } else { >> *sbp = sb2; >> action = ADD_EVENTS; >> } >> } >> } >> . >> . >> } >> >> _______________________________________________ >> freebsd-hackers@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers >> To unsubscribe, send any mail to >> "freebsd-hackers-unsubscribe@freebsd.org" >> >> > -- > /~\ The ASCII Justin C. Walker, Curmudgeon-at-Large > \ / Ribbon Campaign > X Help cure HTML Email > / \ > > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >