On 03-08-08 16:06, Rene Herman wrote:
On 03-08-08 09:58, Manish Katiyar wrote:
ok... I know i am going to be embarrassed but I am confused by the
below function.
I'd not be embarrased...
The last parameter in do_mpage_readpage() is of type get_block_t, but
when passed to block_read_full_page() it gets passed as get_block_t *
The exact nature of get_block_t is important here. Variables of type
get_block_t are function pointers -- have function type:
typedef int (get_block_t)(...);
static struct bio * do_mpage_readpage(............., get_block_t
get_block) {
................
................
if (page_has_buffers(page))
goto confused;
.................
confused:
if (!PageUptodate(page))
block_read_full_page(page, get_block);
.........
}
int block_read_full_page(struct page *page, get_block_t *get_block) {
.........
..........
}
How does this work ? :-( ....... Isn't gcc supposed to catch this and
flag warning unless I am missing something very obvious.
In C, except as an operand of sizeof or unary &, an expression having
function type is automatically converted from function type to pointer
to function.
Or put differently: except for sizeof and unary &, "function_designator"
and "&function_designator" are interchangeable as expressions. You can
therefore write the call as:
block_read_full_page(page, &get_block);
without changing anything, after which I suppose you'd be fine with the
declarations.
Note -- I put that wrong. You could not do that, but you could if
get_block was an actual (direct) function designator, which is the point
I was trying to make.
Now, granted, this specific example is still not nice. I haven't checked
other uses but it appears that block_read_full_page() should've been
declared not with a get_block_t *, but simply with a get_block_t. If you
can convince yourself of such, you could submit it...
Rene.
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ