Re: Linux 2.4.26-rc2

From: Eyal Lebedinsky
Date: Thu Apr 15 2004 - 18:16:05 EST


Marcelo Tosatti wrote:
The void pointer case in here its being done math on without any problem. What is the
problem with void pointer math

There is a problem regarding the C standard. The semantics of 'void *' are well defined
and only allow for limited use. Basically, you can cast any pointer to and from 'void *',
but nothing else.

Pointer math says that 'p+n' means "add to 'p' the value 'n*s' where 's' is the size
on the element that 'p' points to". A 'void *' does not have a defined element size
until it is cast. So, ANSI specifically does not allow any arithmetics on 'void *'.

Some compilers are forgiving and will invent an element size of '1' and allow the
math. We should not rely on such improper usage.

Maybe a cast is
called for in bh_kmap(), like:
return (char *)kmap(bh->b_page) + bh_offset(bh);


Hum, that would fix the warning but I dont see much reasoning behind it.

It will not simply 'fix' the problem, this is one case where a cast is not
a bad thing (i.e. a cheat) but the correct thing to do.

--
Eyal Lebedinsky (eyal@xxxxxxxxxxxxxx) <http://samba.org/eyal/>
-
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/