• @Limonene
    link
    721 day ago

    C when I cast a char * * to a char * * const: ok

    C when I cast a char * * to a char * const *: ok

    C when I cast a char * * to a char const * *: WTF

    C when I cast a char * * to a char const * const *: ok

    • xep
      link
      fedilink
      361 day ago

      The WTF case isn’t allowed because it would allow modification of the const. From https://en.cppreference.com/w/cpp/language/implicit_conversion

      int main() { const char c = ‘c’; char* pc; char** ppc = &pc; const char** pcc = ppc; // Error: not the same as cv-unqualified char**, no implicit conversion. *pcc = &c; *pc = ‘C’; // If the erroneous assignment above is allowed, the const object “c” may be modified. }