3 ms·
I really disagree that this is madness. It may be madness to someone not used to coding in C. But if you code a lot of C you _will_ know when to use which one o
by accatyyc 10y ago
I really disagree that this is madness. It may be madness to someone not used to coding in C. But if you code a lot of C you _will_ know when to use which one of these, and you will know that they're immensely useful.
For example, iterating and adding stuff to arrays:
array[index++] = object;
instead of
array[index] = object;
index += 1;
and the other way around:
array[++index] = object;
instead of:
index += 1;
array[index] = object;
There is no way you will miss incrementing your index here, or do it in the wrong place. This is so common, that as a C-programmer you WILL recognize this pattern.
It's even better when iterating pointers instead of integers. May I ask what the following means to you?
float *float_ptr;
float_ptr += 1;
I think writing ++float_ptr here is just much more clear. Incrementing pointers by integers just feels wrong when what you really are doing is incrementing it with sizeof(float_ptr).
- pka 10y agoUntil the logic is complex enough and you screw it up. Then you write over '\0' in some string and have a root exploit. Congratulations! float *float_ptr; float_ptr += 1; is no more confusing than float float_ptr[...]; float_ptr[1];