Re: GHashTable and const



On Fri, 2008-07-04 at 22:42 -0400, Mark Mielke wrote:
[snip]
> Why would a function taking a const parameter be calling a function with 
> the parameter that isn't defined to take a const?

Because const means what you say it means. The compiler can't know. For
instance, an internal cache or reference count may change during the
call of a public const method. Sooner or later you have something like
this. The compiler can't know what parts of your data are meant to be
const unless you tell it, and you can't tell it in C.

This is why C++ has the mutable keyword. Without it const is almost
useless with anything but simple types (const gchar*, for instance, or
structs containing ints) and that's why it's not used often in C.
 
[snip]
> The main issue with glib, though, is history. Most of the programming 
> world is happy with using const, so I don't buy that the glib developers 
> are smarter in their choice not to.

They've made their choices based on experience and knowledge.

I am very strict about use of const in my C++ code. I'm careful about
its use in C.

>  The choice was wrong. But, it's 
> water under the bridge. Life goes on. The question is now whether it's 
> worth it to change - and I suspect the answer is no.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]