Date: Sat, 6 Mar 1999 14:17:52 -0500 (EST) From: Brian Feldman <green@unixhelp.org> To: Nate Williams <nate@mt.sri.com> Cc: John Polstra <jdp@polstra.com>, current@FreeBSD.ORG Subject: Re: callout changes nit Message-ID: <Pine.BSF.4.05.9903061414040.20711-100000@janus.syracuse.net> In-Reply-To: <199903061834.LAA24560@mt.sri.com>
index | next in thread | previous in thread | raw e-mail
On Sat, 6 Mar 1999, Nate Williams wrote:
> > > > > I make a habit of checking out any interesting kernel changes in full, and one
> > > > > thing I found in the recent diff by Mr. Wollman for kern_timeout.c is:
> > > > >
> > > > > +void
> > > > > +callout_init(c)
> > > > > + struct callout *c;
> > > > > +{
> > > > > + bzero(c, sizeof c);
> > > > > }
> > > > >
> > > > > That doesn't look correct, does it?
> > > >
> > > > Agreed. I think it should be "sizeof *c".
> > >
> > > Ahh, I see. I think it should say
> > >
> > > bzero(c, sizeof(struct callout));
> > >
> > > To avoid the compiler using the size of the pointers et. al.
> > >
> >
> > I prefer to do this in my own code, usually. However, using *c doesn't
> > "use the size of the pointer".
>
> Understood, but the point being that Garrett is an experienced
> programmer, and made this mistake. The latter version avoids any
> possibilities of said mistake.
>
It's just as easy to make the mistake of typing sizeof(struct foo *); I think
there should perhaps be a warning in gcc/egcs about this, like
-Wpointer-sizeof that would warn if you try sizeof(c) where c is a pointer,
but not sizeof(*c) or sizeof(void *). It would help find this kind of
thing, but of course would only be enabled by user-choice, not by default.
Maybe I should just write my own linter instead :)
>
>
> Nate
>
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-current" in the body of the message
>
Brian Feldman _ __ ___ ___ ___
green@unixhelp.org _ __ ___ | _ ) __| \
http://www.freebsd.org/ _ __ ___ ____ | _ \__ \ |) |
FreeBSD: The Power to Serve! _ __ ___ ____ _____ |___/___/___/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9903061414040.20711-100000>
