[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <45A24D1A.7020004@gmail.com>
Date: Mon, 08 Jan 2007 14:54:34 +0100
From: Rene Herman <rene.herman@...il.com>
To: Rolf Eike Beer <eike-kernel@...tec.de>
CC: "Ahmed S. Darwish" <darwish.07@...il.com>,
linux-kernel@...r.kernel.org
Subject: Re: [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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists