Re: Why is the kfree() argument const?

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Andy Lutomirski <luto@...>
Cc: <linux-kernel@...>, Linus Torvalds <torvalds@...>, David Schwartz <davids@...>, Johannes Weiner <hannes@...>, <clameter@...>, <penberg@...>
Date: Friday, January 18, 2008 - 3:14 pm

On Friday 18 January 2008 05:54:12 am Andy Lutomirski wrote:

That's absolutely not true.

Let's unravel the code, by fixing usage of 'x' (which seems to vary at will 
between value and pointer in the above example), and by replacing printf with 
another opaque function. Our decls:
	void foo(const int *ptr);
	void bar(int val);
You're saying that this:
	foo(&x);
	bar(x);
can be reordered into this:
	bar(x);
	foo(&x);

No way. First, the way that const is currently defined, the compiler cannot 
assume that the value of x did not change while foo was executing. So, it 
will not only be forced to leave the two functions in that order, it will 
even reload the value of x before passing it into bar. Go figure.

Second, even if const did have stronger semantics that forbade the value of x 
from being modified during execution of foo, the compiler still could not 
reorder the two function calls, before it cannot assume that the two 
functions (in their internal implementations) do not touch some other, 
unknown to this code, global variable.

-- Vadim Lobanov
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 5:25 pm)
Re: Why is the kfree() argument const?, Jakob Oestergaard, (Fri Jan 18, 5:48 am)
Re: Why is the kfree() argument const?, Björn, (Fri Jan 18, 9:31 am)
Re: Why is the kfree() argument const?, Jakob Oestergaard, (Fri Jan 18, 10:53 am)
Re: Why is the kfree() argument const?, Giacomo A. Catenazzi, (Fri Jan 18, 7:47 am)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 3:06 pm)
Re: Why is the kfree() argument const?, Jakob Oestergaard, (Fri Jan 18, 10:39 am)
RE: Why is the kfree() argument const?, David Schwartz, (Thu Jan 17, 6:28 pm)
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 7:10 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Thu Jan 17, 8:56 pm)
RE: Why is the kfree() argument const?, Linus Torvalds, (Thu Jan 17, 9:15 pm)
Re: Why is the kfree() argument const?, Giacomo Catenazzi, (Fri Jan 18, 3:51 am)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 4:30 am)
Re: Why is the kfree() argument const?, Giacomo Catenazzi, (Fri Jan 18, 4:20 am)
Re: Why is the kfree() argument const?, Andy Lutomirski, (Fri Jan 18, 9:54 am)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 3:14 pm)
Re: Why is the kfree() argument const?, Zan Lynx, (Fri Jan 18, 3:31 pm)
Re: Why is the kfree() argument const?, Vadim Lobanov, (Fri Jan 18, 3:55 pm)
Re: Why is the kfree() argument const?, Andy Lutomirski, (Fri Jan 18, 9:53 am)
Re: Why is the kfree() argument const?, Olivier Galibert, (Fri Jan 18, 1:24 pm)
Re: Why is the kfree() argument const?, J.A. , (Fri Jan 18, 6:29 pm)
Re: Why is the kfree() argument const?, Krzysztof Halasa, (Fri Jan 18, 7:44 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Fri Jan 18, 1:02 am)
Re: Why is the kfree() argument const?, DM, (Fri Jan 18, 2:06 pm)
Re: Why is the kfree() argument const?, Olivier Galibert, (Fri Jan 18, 1:37 pm)
RE: Why is the kfree() argument const?, Linus Torvalds, (Fri Jan 18, 12:10 pm)
RE: Why is the kfree() argument const?, David Schwartz, (Fri Jan 18, 4:55 pm)
Re: Why is the kfree() argument const?, Chris Friesen, (Fri Jan 18, 11:38 am)