[lkml]   [2008]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: Why is the kfree() argument const?
    On Thursday 17 January 2008 11:51:49 pm Giacomo Catenazzi wrote:
    > Linus Torvalds wrote:
    > > No, I'm saying that "const" has absolutely *zero* meaning on writes to an
    > > object through _other_ pointers (or direct access) to the object.
    > Hints: "restrict" is the C99 keyword for such requirement (or better
    > "const restrict")

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

    > BTW I think C use non const free as a BIG warning about not to be
    > to "smart" on optimization.

    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

     \ /
      Last update: 2008-01-18 09:33    [W:0.022 / U:385.568 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site