Imagine I have this C function (and the corresponding prototype in a header file)
void clearstring(const char *data) {
char *dst = (char *)data;
*dst = 0;
}
Is there Undefined Behaviour in the above code, casting the const
away, or is it just a terribly bad programming practice?
Suppose there are no const-qualified objects used
char name[] = "pmg";
clearstring(name);
const
has been added in a cast, the same way it detects thatchar *dst = data;
is illegal. Obviously there are some pointless things that the standard permits for historical reasons, but I claim that this is not one of them :-) – Makedamakefast