Hi, all.
How does this 'sizeof(*area)' work? I think the reason is the sentence in
C99: If the operand has type ¡®¡®pointer to type¡¯¡¯, the result has type
¡®¡®type¡¯¡¯, but I'm not sure. Could someone ensure me or explain it more?
In linux\mm\vmalloc.c,
struct vm_struct * get_vm_area(unsigned long size, unsigned long flags)
{
unsigned long addr;
struct vm_struct **p, *tmp, *area;
area = (struct vm_struct *) kmalloc(sizeof(*area), GFP_KERNEL); // I'm
wondering how this sizeof works.
if (!area)
return NULL;
...
}
According to C99:
sizeof unary-expression
sizeof ( type-name )
4 The unary * operator denotes indirection. If the operand points to a
function, the result is
a function designator; if it points to an object, the result is an lvalue
designating the
object. If the operand has type ¡®¡®pointer to type¡¯¡¯, the result has type
¡®¡®type¡¯¡¯. If an
invalid value has been assigned to the pointer, the behavior of the unary *
operator is
undefined. 72)
NOTE: Among the invalid values for dereferencing a pointer by the unary *
operator are a null pointer, an
address inappropriately aligned for the type of object pointed to, and the
address of an automatic
storage duration object when execution of the block with which the object is
associated has
terminated.
Thanks.
Best Regards,
Xiangliang Meng