this post was submitted on 08 Jan 2025
821 points (98.1% liked)

Programmer Humor

19935 readers
3302 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] Limonene 75 points 3 days ago (2 children)

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

[–] [email protected] 41 points 3 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. }

[–] [email protected] 23 points 3 days ago

Please stop, I have CPTSD.