I was wondering if the implicit conversion to a pointer to a const data type is somewhere defined in the C11 standard:
T x;
const T *p = &x;
A pointer to an object of type T
is implicitly converted into a pointer to an object of type const T
. Is this implicit conversion somewhere defined in the C11 standard? (I know that it makes sense to allow this and how useful it is. I'm just curious to know where it is defined in the standard)
Furthermore, is an implicit conversion from type T**
to const T**
forbidden according to C11?
T *p;
const T **pp = &p;
This is a well known problematic part and therefore GCC and LLVM/clang raise a warning. Still I'm wondering if this is allowed according to the C11 standard or not. I only found in §6.5.16.1P6 a comment that this should be a constraint violation. However, I do not see which constraint should be violated. Again I know that this should be prohibited and that this implicit conversion can lead to subtle problems. I'm just curious to know if this is (un)defined behaviour according to C11.
Again, my two questions are not about if this is good or not (which is answered multiple times here) but how/where the C11 standard defines this.
Just for the sake of completeness here is a link to why the second example is problematic: http://c-faq.com/ansi/constmismatch.html