Re: GHashTable and const



ext Havoc Pennington wrote:
Hi,

This is in the archives a bunch of times, for example the first google
hit I got was
http://mail.gnome.org/archives/gtk-devel-list/2001-May/msg00485.html

Ah, sorry, I only researched about GHashTable.

Whether you agree or not, the GLib types don't use const in their API,
so if you try to use const yourself on these types you're just signing
up for pain. It won't work well or do anything useful. (If _all_ the
methods on an object are non-const, all the const keyword does is make
you do a bunch of casts.)

While I tend to agree that const in C is of limited use, I find it a nice way to tell the users of an API not to modify/free certain data. So, when I am the owner of a GHashTable and I'd like to have others access it in read-only mode, I'd use a const modifier on it.

On your past mail, you write that const is not useful in C, but on the other hand you don't write that it's harmful either. If I proposed a patch which adds some "const" here and there, would that be discarded a priori, or would it undergo a serious consideration?

To put some more meat into the discussion, I point out that GValue's APIs make heavy use of the const modifier, and from the user point of view that's very helpful.

Ciao,
  Alberto

--
http://www.mardy.it <-- Geek in un lingua international!


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