On Jan 8, 1:45*pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> > thanks for your answer, in fact, I don't need to change the
> > qualifiers, rather I'm looking for a way to create a generic data
> > structure that can can be used with const generic pointer or non const
> > generic pointer, preventing the user from casting if I would hard code
> > the qualifier.
>
> If you hard-code the const, why does the user have to cast?
If I hard-code the const and the user put a non const data, it makes
no problem, but if he wants to get back his data that is now stored in
a pointer to const, he is forced to cast.
> > Think of a generic linked list where you can put const
> > data or variable data without casting because I would code void * data
> > and the user want to put a const char *.
>
> As a rule, generic container structures don't know enough about the
> data to do anything much with it (they may pass it to a function but
> that is about it). *That makes me wonder why you need the non-const
> data variant.
see above, when you want to get back your data in a pointer to non
const data, you are forced to cast.
> > I hope it is clear, english is not my mother tongue.
>
> Yes, perfectly clear. *Your English is excellent. *While on the
> subject of language, pointers are problematic. *You talk about a
> "const generic pointer or non const generic pointer" but in fact the
> pointer is not const qualified in either case, it is the data pointed
> *to* that is marked const. *This is not a complaint -- everyone drops
> into shorthands like this all the time -- but sometimes it matters and
> it pays to be vigilant for those cases where they might be a
> misunderstanding.
You're right, it's a bad shorthand.
|