4 ms·
BUT clearly there is a world of difference between saying "it would be nice to have char* + char* as a short hand for string concatenation somehow" - which is r
by i_c_b 13y ago
BUT clearly there is a world of difference between saying "it would be nice to have char* + char* as a short hand for string concatenation somehow" - which is roughly what I was saying - versus saying "all operators in a language should be arbitrarily overloadedable", which is roughly how you responded.
Now, I'm not saying there is an obvious way to handle "char* + char" meaningfully or safely in C. But on the other hand,
char stackString = "some literal";
is generally handled in an entirely different fashion from
int myVar = 7;
if both are declared as local stack variables - and C programmers generally have no problem learning that "=" is going to mean something quite special when declaring string literals this way, compared to other data types. Because as you say, it's just one more language rule.
The only real places where I miss operator overloading in C are when dealing with strings in performance non-critical places, any time I'm using 3D vectors, and any time I'm writing matrix math. If those were handled as primitives in the language (and as the string literal example shows, C already does go partway down that road), I'd very happily part with arbitrary operator overloading.
- theseoafs 13y ago> char *stackString = "some literal"; Uh, in what way is that "entirely different" from the int declaration? In both cases, you're just copying a couple words from one place to another, which is what the = operator does. There's nothing "special" about that declaration; we're just writing a pointer into a variable on the stack. My feeling is that you're uncomfortable with C's treatment of strings because you don't entirely understand the memory model.
- i_c_b 13y agoGiven what you've written, I have my own doubts about your understanding too. Unfortunately, that and your proactive psychoanalysis of me are not interesting conversation topics.
- theseoafs 13y agoWell, you could help out my ignorance by explaining what's so special about `char *s = "some string";`.