3 ms·
It does not add a warning for older code. It does not affect existing code in any way. > Exactly equivalent to an already popular practice of passing array and
by WalterBright 3y ago
It does not add a warning for older code. It does not affect existing code in any way.
> Exactly equivalent to an already popular practice of passing array and its length next to each other.
Differences:
1. passing pointer and length next to each other is a convention. This means the compiler doesn't know about it.
2. you cannot turn array bounds checking on and off with a compiler switch (though we strongly recommend leaving it always on)
3. your array bounds checking convention won't be compatible with someone else's code (standardization is a big deal)
4. I've never seen it used for strings. Strings are a major beneficiary of bounds checking
5. You have to document this every time you use it.
6. it's clutter
7. there's no check that the array/length variables are not mixed up or otherwise confused with other variables
Most importantly, making a feature trivial to use makes for at least an order of magnitude increase in adoption of it. And what we want is adoption of it, right?
The proof is that array buffer overflows remain the #1 problem with C bugs.
P.S. I am always amazed at how C++ managed to get users to prefer:
std::vector<int> a;
over:
int[] a;
- pjmlp 3y agoBecause the 2nd is incompatible with copy-paste semantics from C code in C++. We can argue that C++ shouldn't have been that close to C, but that ship has sailed a long time ago.
- WalterBright 3y agoMy proposed new syntax can work with C++, too.