i enjoy how it doesn't even return const char *, just char *. so, naturally:
void *malloc(size_t i) { return strerror(i); }
Conversation
What would you prefer? Statically compiling in every possible string in every possible language?
getting tired of these "omg c/glibc is so cursed lol" threads tbh; reeks of brownie-point farming
(now someone insults me for daring to disagree; that's how this site works right?)
4
8
It can dynamically generate strings for unknown numbers and still return const char*. That just means callers can’t modify the string, it doesn’t restrict strerror’s implementation.
1
18
It can do literally everything. On the other hand, what would be the ownership and lifetime of the returned `const char*` and `char *` values, respectively?
1
2
C99 7.21.6.2 p4 "The array pointed to shall not be modified by the program"
the storage duration seems to not be specified, as far as I can see
1
16
Honestly I think that confusion was me conflating this with functions that *take* (const char *), where one might want the contents of that string to be dynamic, but you're not supposed to do that bc it's supposed to be const
...or something like that I never did much stringop
2
8
The first thing that comes to mind atm is something like e.g. SDL_CreateWindow(), which demands (const char*) for the title, but what if I want it to include a filename or something like that?
oh right you're not supposed to, I guess?? 🤔🥴
2
7
const char* does not mandate the use of a string literal; it just mandates immutability from the moment of casting for the duration of observability as const. make a string, cast its pointer to const pointer, and don't modify the referent anymore
2
30
(also string literals in C aren't const, although their storage is immutable)
2
3
29
Do you have a source?
I tried decltype("...") and it's const char(&)[4], which disputes what you are saying that they aren't typed as const.
3
2
It's different in C and C++ similarly to how 'a' is an int in C and a char in C++. Same goes for true/false with C++ booleans compared to the C macros from stdbool.h which are just int constants.
these are actually things i sometimes ask about (kindly) in interviews, when someone has the fateful "i know C/C++" on their CV
6
16







