Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the different between __declspec(restrict) and __declspec(noalias)

Tags:

c++

visual-c++

What is the different between __declspec(restrict) and __declspec(noalias) I have read this page https://msdn.microsoft.com/en-us/library/k649tyc7.aspx. but not clear what it is. Can someone explain what problem solve by these two annotations.

like image 638
Nayana Adassuriya Avatar asked Mar 17 '23 22:03

Nayana Adassuriya


1 Answers

__declspec(restrict) declares that the return value of a function points to memory that is not aliased. That is, the memory returned by the function is guaranteed to not be accessible through any other pointer in the program.

__declspec(noalias) declares that the function does not modify memory outside the first level of indirection from the function's parameters. That is, the parameters are the only reference to the outside world the function has.

Neither of these solves any problem as such - they are just performance hints to the compiler. Normally, the compiler would need to ensure that things like caching intermediate results in registers or reordering code would not be affected by potential aliasing on function calls; these declarations are your guarantees as a programmer that the compiler does not need to worry about this when compiling these specific functions.

like image 104
jlahd Avatar answered Apr 06 '23 10:04

jlahd