lkml.org 
[lkml]   [2008]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Why is the kfree() argument const?
On Fri, Jan 18, 2008 at 02:31:16PM +0100, Björn Steinbrink wrote:
...
>
> Do you see anything that casts the const away? No? Me neither. Still,
> the memory that p points to was changed, because there was another
> pointer and that was not const.

*another* being key here.

>
> > *That* is the purpose of const pointers.
>
> The only thing that const can tell you is that you should not modify the
> value _yourself_, using that pointer _directly_.

Which is pretty damn useful.

Think about it. Don't you ever use const? Is it ever only in the way?

...
{snip long explanation about how one can avoid the benefits of const, without
using casts}
...
> If you want to restrict the set of pointers that can be invalidated by
> an other pointer, you'll have to use something else because const does
> not talk about invalidating aliasing pointers.
Precisely, so why are we discussing this?

I claim that const is useful. You claim that it can't solve all the worlds
problems. I agree with that, but I maintain it is still useful.

But, in order for it to be useful, it requires that people do not circumvent it
in the wrong places (such as kfree).

--

/ jakob

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

\
 
 \ /
  Last update: 2008-01-18 15:57    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site