What can human beings make out of the restrict qualifier?

后端 未结 6 1540
盖世英雄少女心
盖世英雄少女心 2021-02-04 05:51

If I got the C99 restrict keyword right, qualifying a pointer with it is a promise made that the data it references won\'t be modified behind the compiler\'s back t

6条回答
  •  佛祖请我去吃肉
    2021-02-04 06:42

    This might be an example from an extremely narrow domain, but Altera's Nios II platform is a soft-core microcontroller that you can customize within an FPGA. Then, within the C source code for that micro, you can use a C-to-hardware tool to speed up inner loops using custom hardware, rather than in software.

    In there, use of the __restrict__ keyword (which is the same as C99's restrict) allows the C2H tool to properly optimize the hardware acceleration of pointer operation in parallel instead of sequentially. At least in this case, the restrict is simply not meant for human consumption. See also Sun's page on restrict, where the first line says

    Using the restrict qualifier appropriately in C programs may allow the compiler to produce significantly faster executables.

    If anyone's interested in reading more on C2H, this PDF discusses optimizing C2H results. The section on __restrict__ is on page 20.

提交回复
热议问题