2 ms·
I understand their desire to use a library, but there's a faster and safer way to do this that's more C-like if you have access to the compiler: Just locate an
by gumby 7y ago
I understand their desire to use a library, but there's a faster and safer way to do this that's more C-like if you have access to the compiler:
Just locate anything declared as an array in a particular linker section so the pointer manipulation can be done with two (or one if it's at the top of memory) comparison, possibly even to a constant.
If you do this you can even forbid pointer arithmetic except in actual []-declared memory, and can do transparent bounds checking (&array-1 can hold the array length or, possibly faster, the address of the location after the end of the array).
An advantage of this over the library route is you can prevent pointer/array punning but otherwise allow any C program to work fine. And apart from a few corner cases (there are legit non-array uses of pointer arithmetic, though very few) and noncompliant program can be changed to use [] and still work perfectly fine without this option being used.