[patch] const_cast to be replaced by str_unconst
Roland Illig
roland.illig at gmx.de
Tue Apr 12 10:47:27 UTC 2005
Hi all,
I'd like to introduce a new function:
char *str_unconst(const char *);
The function returns a string that compares equal to its argument, but
does not have the "const" qualifier. Currently it just returns its
argument, cast to (char *).
I like this version much more than the const_cast macro I introduced
some months ago. Compare these:
ms = const_cast(char *, cs);
ms = str_unconst(cs);
The latter is shorter, has fewer chances for typing errors and is not as
powerful as the former. You could have passed an int (or any other
value) before, and that had been converted (or promoted, or whatever
that type cast means in that case) to a char *. That took an important
possibility to check for bugs from the compiler.
There's also the naming issue. Apparently, Bjarne Stroustrup has not had
enough letters to name the const_cast unconst_cast, which would be more
appropriate. The current name is just misleading, so I want to abandon it.
For those of you that are concerned about the performance loss of an
extra function call: It is much more important for the code to be
readable and checkable by the compiler than to be 1 millisecond faster
at all.
Roland
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: str_unconst.patch
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20050412/30e86606/attachment.ksh>
More information about the mc-devel
mailing list