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                                               j...@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 majord...@freebsd.org
with "unsubscribe freebsd-current" in the body of the message

Reply via email to