[AD] constness in ugetx()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hello,

There's a small problem with the constness in ugetx() which I don't
think has been discussed yet. Constness for double pointer parameters,
like the parameter in ugetx(const char **c), works in a slightly
unexpected way: You can't pass a non-const `char **' to it. This is
because inside ugetx() it is allowed to do eg:

   *x = "hello world";

(where "hello world" is a `const char *'), in which case the non-const
`char **' in the calling function would end up pointing to a `const char
**'. But the very purpose of constness is to avoid non-const pointers
pointing to const data. Hence a warning is generated when ugetx() is
called with something that is not const, although for ugetx() it is
perfectly valid to do so. IMHO this is just as bad as generating a
warning when ugetx() is called with something which is const. In my
programs, a file which uses strings typically generates a screenfull of
warnings right now, since ugetx() is a quite frequently used function.
To avoid this warning you have to convert the non-const pointer to a
const pointer, which is not logical. I see three ways that Allegro could
deal with this:

 - Remove constness of the arg to ugetx(). This avoids the problem which
I discussed, but obviously causes the converse problem when ugetx() is
called with a `const char **'. It might also be slightly dangerous to
have the whole API do const checking except for one function.
 - Keep it the way it is, forcing people to explicitly convert things
that aren't const into const. This is not really logical to do either,
but it's indeed the easiest solution :-)
 - Add a new function which can be used for non-const parameters. This
solves both problems, but adds a new (sort of silly) function to the
api.

In both of the two first cases, we could add a C++ function which
overloads ugetx() with the appropriate constness, but that's not
possible in C.

What do you think? Is this worth bothering at all, and if so, which
solution should be used?

Sven



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/