Re: GHashTable and const



ext Brian J. Tarricone wrote:
Now, that's for C. For C++ passing a const pointer to a function expecting a non-const pointer actually a hard *error*[1]. So the API couldn't be changed in this way without likely breaking any C++ application that uses these glib data structures.

Yes, but this is not our case: by introducing const in some of the API parameters we don't restrict their usage: you can always pass them a non-const variable in C++ too, right?

Personally, I mainly see it as a hint to the programmer so I can tell at a glance that the function doesn't modify the parameter (const) or may modify the parameter (non-const). I'd agree that any speed benefits are probably very small (if nonexistent), so the burden would be on someone to benchmark to prove otherwise. If the API were being designed from scratch, I'd say sure, use const as a semantic identifier. But at this point it's just too late to do it without breaking C++ programs that use glib.

I might be ignorant on C++, but I don't see why this would break anything. I'm not saying that g_hash_table_new() must return a const GHashTable, but I'd like to be able to pass a const GHashTable to a function like g_hash_table_size() without warnings or casts.

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]