3 ms·
> Inline side effects like that are a mess. Without looking it up, I could not even tell you if the sequence point ordering of that kind of expression in genera
by kllrnohj 8y ago
> Inline side effects like that are a mess. Without looking it up, I could not even tell you if the sequence point ordering of that kind of expression in general is defined in C!
What are you calling "inline side effects" here? The ++ operator or the += operator? Because the index-of a ++ operator is extremely well defined.
In fact that code snippet works in every language with a ++ operator exactly as you'd expect, there's really no tricks in play here. Drop that code into C, C++, Java, JavaScript, etc... and it does the exact same thing in all of them via well-defined rules. It will append 'a' to data[index] then increment index.
We're not even into the wierd land of mixing bitwise & boolean operators on the same line where you operator precedence becomes non-obvious.
- adrianratnapala 8y ago> It will append 'a' to data[index] then increment index. Of course, you can always do stupid stuff to make life difficult. In C++ int data[100]; memset(data, 0, sizeof(data)); int &index = data[0]; data[index++] = 'a'; Which cell is the ++ applied to, data[0] or data[97]?