[lkml]   [2005]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: p = kmalloc(sizeof(*p), )
On 9/19/05, Robert Love <> wrote:
> On Sun, 2005-09-18 at 11:06 +0100, Russell King wrote:
> > +The preferred form for passing a size of a struct is the following:
> > +
> > + p = kmalloc(sizeof(*p), ...);
> > +
> > +The alternative form where struct name is spelled out hurts readability and
> > +introduces an opportunity for a bug when the pointer variable type is changed
> > +but the corresponding sizeof that is passed to a memory allocator is not.
> Agreed.
> Also, after Alan's #4:
> 5. Contrary to the above statement, such coding style does not help,
> but in fact hurts, readability. How on Earth is sizeof(*p) more
> readable and information-rich than sizeof(struct foo)? It looks
> like the remains of a 5,000 year old wolverine's spleen and
> conveys no information about the type of the object that is being
> created.

6. The attribute size is _firstly_ an attribute of the data type, not
of the variable. So sizeof(type) is a bit saner than sizeof(var).
While allocating, we are allocating an instance of the type and we
don't care which instance it would be but we care what data type it

Coywolf Qi Hunt
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-09-19 08:50    [W:0.076 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site