add 'restrict' keyword to pointers per C11AnnexK.
Add 'restrict' keyword to all implemented interfaces per the C11 Annex K standard. "The restrict keyword is a declaration of intent given by the programmer to the compiler. It says that for the lifetime of the pointer, only the pointer itself or a value directly derived from it (such as pointer + 1) will be used to access the object to which it points. This limits the effects of pointer aliasing, aiding optimizations." per [wikipedia](https://en.wikipedia.org/wiki/Restrict). Note that compilers often implement a compiler-specific keyword version of 'restrict' and may or may not actually define the standard 'restrict' keyword itself. For instance: GCC: __restrict__ and __restrict MSVC: __restrict IAR: _Restrict Renesas RX Hew: _Restrict and restrict We solved this in our code by using a "restrict.h" header which would conditionally define the restrict keyword for known compilers. Another method in cmake is to test compiling code with different versions of the 'restrict' keyword to determine which one is available and then mapping the 'restrict' keyword to whatever is available. However, this repository in `configure.ac` uses `AC_C_RESTRICT` keyword which gnu [defines](https://www.gnu.org/software/autoconf/manual/autoconf-2.60/html_node/C-Compiler.html) as: > If the C compiler recognizes the restrict keyword, don't do anything. If it recognizes only a variant spelling (__restrict, __restrict__, or _Restrict), then define restrict to that. Otherwise, define restrict to be empty. Thus, programs may simply use restrict as if every C compiler supported it; for those that do not, the makefile or configuration header defines it away. So there should be no harm in inserting the `restrict` keyword for all applicable pointers per the standard since it would either be removed or matched to each compiler's keyword. The changes in this commit were co-authored with Arjun Gour, my coworker, who has approved of submitting his work back to this open source library.
parent
0670c902
Please register or sign in to comment