I understand that implicit conversion from non-const to const is not dangerous when handling values, by example:
int mutable = 5; const int immutable = mutable; However, when working with pointers, I can do something as follows:
int some_number = 5; int *mutable = &some_number; const int *immutable = mutable; // <= Legal, but isn't it dangerous? // Let's try to break const printf("%d\n", *immutable); // Prints 5 mutable[0] = 10; printf("%d\n", *immutable); // Prints 10 By the way, for double pointers this is not allowed (at least you get a warning)! See this question and the references therein.
some_number) is not const. Having const on a pointer target doesn't mean "guaranteed to yield the same value if you read it twice, with some other stuff happening in between"constas promise. Why any one want to break his own promise?constqualified pointer in your code!