5 ms·
I know that. I meant that “abc” + “def” is most likely illegal (although “abc” + ‘d’ is not).
by tgv 5y ago
I know that. I meant that “abc” + “def” is most likely illegal (although “abc” + ‘d’ is not).
- wott 5y ago> I meant that “abc” + “def” is most likely illegal That would be adding 2 pointers, and that's indeed illegal. However, you can subtract them: “abc” - “def” . Now, the result is not a pointer any more, it's a ptrdiff_t (an integer type), so most compilers will warn if you try to assign that to a char *.
- kazinator 5y agoYou started talking about "adding strings" in a thread about adjacent literals, without mentioning any + operator.. String catenation ("adding") by adjacency (no visible operator) is a thing; "add" doesn't imply that we are talking about a + operator: $ awk 'BEGIN { x = "abc-" 2 + 2 "-def"; print x}' abc-4-def
- tgv 5y agoBecause the parent compared Python's behavior to that of C. The difference of course is that adding strings doesn't make sense in C, so there's no danger of misinterpreting "abc" "def" in C, as there is in Python.
- kazinator 5y agoThe same comma typo bug could happen in C. execl("/bin/sh", "/bin/sh", "-c" "echo foo", (char *) NULL); Here we get one "-cecho foo" argument passed to the shell instead of two, so it can't work. Initializers are another example: char *strArray[] = { "how", "now" "brown", "cow" }; In non-variadic function and macro calls, you will most likely get an insufficient arguments error, unless another mistake compensates for that.