Re: lack of const in glib::GDate
- From: Havoc Pennington <hp redhat com>
- To: bds02 uow edu au
- Cc: gtk-list gnome org
- Subject: Re: lack of const in glib::GDate
- Date: 24 Mar 2001 11:41:46 -0500
Ben Stanley <bds02 uow edu au> writes:
>
> I'm using the GDate stuff in glib-1.2.9, and I noticed that const has
> not been used
> anywhere.
>
> I was wondering if there was a reason that it was designed that way, and
> if there are any plans for changing it in the future.
>
> I also noticed that const has been used in other places in the API.
>
Many of the const operations on GDate actually do mutate the struct,
because GDate has two different representations of the date which it
keeps updated according to what you're doing. C has no mutable
keyword. If you have a 'const GDate' then it could be in read-only
memory, and the GDate methods would crash.
Basically const isn't worth much on plain structs, because of no
'mutable', and also because of this:
struct Foo
{
gchar *field;
};
const Foo *foo = foo_new ();
foo->field[0] = 'a'; /* no warning at all */
i.e. the const isn't "inherited" by member variables. This is why
const is useless on GList, for example:
GList *list;
const GList *clist;
list = clist->next->prev; /* no warning, and list == clist. */
Anyhow, short answer, the reason C programmers don't use const is that
without C++ features such as mutable and accessor functions, const is
not very useful.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]