4 ms·
Indeed, this is what many people do. But even if you use dynamic memory, if you replace pointer arithmetic by array indexing, you get bounds checking. And in C
by uecker 1y ago
Indeed, this is what many people do. But even if you use dynamic memory, if you replace pointer arithmetic by array indexing, you get bounds checking. And in C this also works for arrays of run-time length.
- 1718627440 1y agoBut can't I put any pointer arithmetic in array brackets, so it wouldn't limit anything?
- uecker 1y agoWhatever index you compute can be checked against a bound.
- 1718627440 1y ago2[a*b] What bound?
- uecker 1y agoThis does not even compile. For array indexing, array[expression] if "array" has a bound whatever expression evaluates to can be checked against the bound of array. If "array" is not a bounded array but a pointer or an unbounded array, then this does not work, but my point is that it is easy to avoid such code.