i'm gonna be honest.
-
i'm gonna be honest. while i understand the difference in C between
const char* ptr
and
char *const ptr
i will never be able to remember the 2nd form exists let alone use it
-
i'm gonna be honest. while i understand the difference in C between
const char* ptr
and
char *const ptr
i will never be able to remember the 2nd form exists let alone use it
@eniko I struggled to remember exactly how each of these worked until someone told me that I should read it from right to left.
i.e.
`const char*` is a pointer to a char constant. So the thing being pointed to is const.
And `char * const` is a constant pointer to a char. So the pointer itself is const. -
@eniko I struggled to remember exactly how each of these worked until someone told me that I should read it from right to left.
i.e.
`const char*` is a pointer to a char constant. So the thing being pointed to is const.
And `char * const` is a constant pointer to a char. So the pointer itself is const.@karadoc@aus.social @eniko@mastodon.gamedev.place A good way to read C type declarations is the "Spiral Rule". see: https://ongspxm.gitlab.io/reading/2021/01/the-spiral-rule-in-c/