lkml.org 
[lkml]   [2005]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: p = kmalloc(sizeof(*p), )
On 9/18/05, Robert Love <rml@novell.com> wrote:
> 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.

Yes it does. The semantics are clearly "I want enough memory to hold
the type this pointer points to." While sizeof(struct foo) might seem
more readable, it is in fact not as you have no way of knowing whether
the allocation is correct or not by looking at the line. So for
spotting allocation errors with grep, the shorter form is better (and
arguably less error-prone).

Pekka
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-09-20 12:05    [W:0.189 / U:0.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site