[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20080118232911.22c9d8d5@werewolf>
Date: Fri, 18 Jan 2008 23:29:11 +0100
From: "J.A. Magallón" <jamagallon@....com>
To: "Linux-Kernel, " <linux-kernel@...r.kernel.org>
Subject: Re: Why is the kfree() argument const?
On Fri, 18 Jan 2008 18:24:29 +0100, Olivier Galibert <galibert@...ox.com> wrote:
> On Fri, Jan 18, 2008 at 08:53:44AM -0500, Andy Lutomirski wrote:
> > I'd say this implies the exact opposite. It almost sounds like the
> > compiler is free to change:
> >
> > void foo(const int *x);
> > foo(x);
> > printf("%d", x);
> >
> > to:
> >
> > void foo(const int *x);
> > printf("%d", x);
> > foo(x);
>
> That's only if neither function has side effects noticeable by the
> other. Invalidating the pointer in (k)free is rather noticeable.
>
That's what __attribute__ ((pure)) is for, but if none of the
functions is pure, the compiler can not be sure about side effects
and can not reorder things. Don't forget that functions can do
anything apart from mangling with their arguments.
And allocator/deallocator functions never can be pure, they must
change global data, the pool of free blocks.
--
J.A. Magallon <jamagallon()ono!com> \ Software is like sex:
\ It's better when it's free
Mandriva Linux release 2008.1 (Cooker) for i586
Linux 2.6.23-jam05 (gcc 4.2.2 20071128 (4.2.2-2mdv2008.1)) SMP PREEMPT
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists