Re: Why is the kfree() argument const?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Vadim Lobanov
Date: Friday, January 18, 2008 - 1:30 am

On Thursday 17 January 2008 11:51:49 pm Giacomo Catenazzi wrote:

The restrict keyword controls aliasing, to be exact. And I'm skeptical that 
inserting const there would do anything at all.


I must ask what relationship you think the const keyword has to compiler 
optimizations. I know of none, and I've yet to see that keyword cause any 
difference in the resulting assembly. It forces you to make your code clean 
and well-structured, but that's about it.

Of course, it would be an interesting experiment to potentially redefine the 
const keyword to have stronger semantics, such as having the compiler assume 
that a function taking a const pointer argument will not modify the memory 
the pointer points to, and thus saving itself a memory load in the caller 
after the function executes, as long as the data is not global. I imagine 
that this would lead to some simple and measurable optimizations, all the 
while (this is where I get into hand-waving territory) breaking a minimum 
amount of code in current existence.

But that is emphatically not how C is currently defined, and you're basically 
inventing an entirely new language... C2009 perhaps? :-)

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