lkml.org 
[lkml]   [2007]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH UPDATED 2.6.20-rc3] Remove all the unneeded k[mzc]alloc casts
On 01/08/2007 01:10 PM, Rolf Eike Beer wrote:

> Ahmed S. Darwish wrote:

>> - struct intmem_allocation* alloc =
>> - (struct intmem_allocation*)kmalloc(sizeof *alloc, GFP_KERNEL);
>> + struct intmem_allocation* alloc = kmalloc(sizeof *alloc,
>> + GFP_KERNEL);
>
> sizeof(*alloc) (see Documentation/CodingStyle)

Please do not advice that. The CodingStyle document only says "are
usually used with parentheses in Linux, although they are not required
in the language", nothing more. While for the most part a personal style
issue, there are reasons for using "sizeof *ptr":

-- sizeof is not a function but an operator: you don't write
"if (!(i))" or -(5) either.

-- it's usually "better" to sizeof the variable then it is to sizeof the
type since it makes the code resistant to type changes (for
instance foo_t -> struct foo changes)

Since you _do_ need the parens with a type, getting used to writing
"sizeof foo" without them will then alert you and reader to the fact
that something special is happening when you do see/use them.

If not enough of a reason to make "sizeof foo" the rule, please leave
this up to personal preference.

Rene.

-
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: 2007-01-08 14:59    [W:0.068 / U:0.828 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site