Earlier quoted context omitted.
- In your example there's no guarantee that the length will be accurate, or that the data hasn't been modified independently elsewhere in the program. - In other words you've created a fantastic shoe-gun. One update line missed (either length or data, or data re-used outside the struct) and your "simple" struct is a huge headache, including potential security vulnerabilities. - Re-implementing a common error prone th…
>In your example there's no guarantee that the length will be accurate, or that the data hasn't been modified independently elsewhere in the program. And having a special data-and-length type would make these guarantees... how? You're ultimately going to need to be able to create these objects from bare data and length somehow, so it's a case of garbage-in-garbage-out.
int raw_arr[4] = {0,0,0,0};
struct SmartArray arr;
arr.length = 4;
arr.val = raw_arr;
some_function(arr);
Smart declaration with custom type: (assume that they'll come up with a good syntax) smart_int_arr arr[4] = {0,0,0,0};
some_function(arr);
With the custom struct, it requires the number `4` to be typed twice manually, while in the second it only needs a single input.