Re: [PATCH 1/2] iWARP Connection Manager.

From: Roland Dreier
Date: Wed May 31 2006 - 17:53:31 EST


This is a silly thing to argue about, but...

> 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.

I would argue that this is talking about sizeof(*p) vs. sizeof (struct foo)
rather than sizeof(*p) vs. sizeof *p.

You wouldn't write:

return(*p);

but rather

return *p;

And sizeof is an operator not a function, so I think the same usage
would apply.

With that said the prevalent kernel usage does seem to be sizeof(*foo)
(by about 10 to 1). But I can't help feeling it looks silly.

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