What can human beings make out of the restrict qualifier?

后端 未结 6 1434
盖世英雄少女心
盖世英雄少女心 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:40

    Someone more familiar with the standard could probably give a better answer, but I'll give it a shot.

    "Data won't be modified behind the compiler's back" sounds more like the opposite of "volatile" to me.

    "const" means the data won't be modified in front of the programmer; that is, she can't modify the data through the signifier marked as "const" (I write "signifier" because in int const *pi, the name pi isn't const, but *pi is). The data might be modifiable via another signifier (non-const data can be passed to a function as const data, after all).

    That "restrict" qualifies pointers is the key. Pointers are the only way to alias data in C, so they're the only way that you can access some piece of data via two different names. "restrict" is all about limiting data access to one access path.

提交回复
热议问题