Re: [PATCH UPDATED 2.6.20-rc3] Remove all the unneeded k[mzc]alloc casts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux