A const use-case I would NOT like to see replicated
Bill Baxter
dnewsgroup at billbaxter.com
Thu Jun 21 19:06:22 PDT 2007
Tim Keating wrote:
My main issue is with const-correct programs passing data to
> non-const-correct libraries. For example, consider extracting string
> data from a std::string to pass to a library written in C (using the
> c_str() member func). If the function you want to call takes a const
> char*, as it should, then great, you're fine. If it takes only a char*
> (which I have seen happen plenty of times), you're screwed. Your choices
> are:
Having const can certainly lead to lots of casts here and there when
working with code that isn't const aware. No question about that. But
the casts are there for a reason -- they're reminding you and other
programmers that come along later "this is a potentially unsafe operation".
Ok, but I can see that it might be nice to have a way to import a module
such that it ignores const issues. Like casting away const on all the
functions in a module with one line of code. Like Don's "break const"
-- something like
break(const) import legacy_module;
I think this could be tricky to implement though.
--bb
More information about the Digitalmars-d
mailing list