[AD] The details of 'const'

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


Here's a quote from const._tx:

"Please note that for the Unicode function ugetx(), I have provided an
alternative version ugetxc(), which takes a `const char**' parameter as
opposed to a `char**' parameter. This is because it is valid to pass either
a `char**' or a `const char**', but unfortunately there is no way to tell
the compiler exactly what we mean."

In response to a conversation thread on allegro.cc, I did some experiments
with the 'const' keyword in DJGPP. I discovered the following:

const char ** // vp to vp to const char
const char *const * // vp to cp to const char
const char **const // cp to vp to const char
const char *const *const // cp to cp to const char

'vp' and 'cp' are variable and constant pointers respectively.

"char const ..." and "const char ..." behave the same.

Hence, at least in DJGPP, it *is* possible to tell the compiler exactly what
we mean. In this case, we want a pointer to a variable pointer to a constant
string, so "const char **" is fine for ugetx(). It just means that the
string is constant; not the pointer.

Can someone please tell me whether this is the same for all compilers, or
whether it's just DJGPP being nice? If it's the same for all compilers, we
shouldn't need ugetxc(). But of course I have to check first.

Ben Davis



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