822
you are viewing a single comment's thread
view the rest of the comments
[-] Limonene@lemmy.world 76 points 2 days 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@fedia.io 41 points 2 days 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. }

[-] SaharaMaleikuhm@feddit.org 23 points 2 days ago

Please stop, I have CPTSD.

this post was submitted on 08 Jan 2025
822 points (98.0% liked)

Programmer Humor

19932 readers
2081 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS