Date: Sat, 06 Mar 1999 11:00:05 -0800 (PST) From: John Polstra <jdp@polstra.com> To: Nate Williams <nate@mt.sri.com> Cc: current@FreeBSD.ORG Subject: Re: callout changes nit Message-ID: <XFMail.990306110005.jdp@polstra.com> In-Reply-To: <199903061736.KAA24445@mt.sri.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Nate Williams wrote: >> > +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. This is largely a matter of taste, so we don't need to agree on it. :-) But I do have a specific reason for preferring the "sizeof *c" form. Namely, it reduces redundancy. The advantage is best seen if you consider making a macro for clearing a structure. Here are two possibilities: #define CLEAR_STRUCT(ptr) bzero((ptr), sizeof *(ptr)) #define CLEAR_STRUCT(ptr, type) bzero((ptr), sizeof(type)) In this context, the 1-parameter form is indisputably less error-prone. Of course, the context of the original example was different. So I'm satisfied to say we are both "right". John --- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Nobody ever went broke underestimating the taste of the American public." -- H. L. Mencken To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.990306110005.jdp>