3 ms·
Because C is a thin layer above assembly language. A pointer fits in one register, { ptr, count } would require two registers. Also if the count is being passed
by glxxyz 6y ago
Because C is a thin layer above assembly language. A pointer fits in one register, { ptr, count } would require two registers. Also if the count is being passed around, it should surely be checked when doing ptr + i, which slows things down further and is unnecessary if the caller knows what they are doing. If you start trying to make C safe and idiot-proof you also make it slower.
- alkonaut 6y agoIsn’t ptr+count always two registers if passed as two parameters too? It seems like just a syntactic difference. A ptr to an array of unknown length can’t be used without the length being passed around next to it whereever it’s passed. You cant deref ptr+i without knowing that it’s under length etc. Two bits of data that belong together seems like they would be convenient to pass (or return!) as one argument or return value. It’s especially terrible with methods that e.g take two lists and return a third. That should be two arguments and a return value, not six arguments.
- pjmlp 6y agoYet plenty of Assembly languages have opcodes for bounded checking memory accesses, some of them in computer systems developed in the early 60's, 10 years before C was born.