by moonchild · 5y ago · 0 comments
void mutate(const int *x) {
*(int*)x = 5;
}
int main() {
int a;
mutate(&a); // ok
const int b;
mutate(&b); // undefined behaviour
}So then actually no - it's not guaranteed to be portable. That non-const location qualification of course means portable code cannot just cast const pointers to non-const.