You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp/noalias.md
+12-9Lines changed: 12 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "noalias | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "11/04/2016"
4
+
ms.date: "02/09/2018"
5
5
ms.reviewer: ""
6
6
ms.suite: ""
7
7
ms.technology: ["cpp-language"]
@@ -25,13 +25,15 @@ ms.workload: ["cplusplus"]
25
25
26
26
If a function is annotated as `noalias`, the optimizer can assume that, in addition to the parameters themselves, only first-level indirections of pointer parameters are referenced or modified inside the function. The visible global state is the set of all data that is not defined or referenced outside of the compilation scope, and their address is not taken. The compilation scope is all source files ([/LTCG (Link-time Code Generation)](../build/reference/ltcg-link-time-code-generation.md) builds) or a single source file (non-**/LTCG** build).
27
27
28
-
## Example
28
+
The `noalias` annotation only applies within the body of the annotated function. Marking a function as `__declspec(noalias)` does not affect the aliasing of pointers returned by the function.
29
+
30
+
For another annotation that can impact aliasing, see [__declspec(restrict)](../cpp/restrict.md).
29
31
30
-
The following sample demonstrates using `__declspec(restrict)` and `__declspec(noalias)`. Normally, memory returned from `malloc` is `restrict` because the CRT headers are decorated appropriately.
32
+
## Example
31
33
32
-
However, in this example, the pointers `mempool` and `memptr` are global so the compiler has no assurance that the memory is not subject to aliasing. Decorating the functions that return pointers with `__declspec(restrict)` tells the compiler that the memory pointed to by the return value is not aliased.
34
+
The following sample demonstrates the use of `__declspec(noalias)`.
33
35
34
-
Decorating the function in the example that accesses memory with `__declspec(noalias)`tells the compiler that this function does not interfere with the global state except through the pointers in its parameter list.
36
+
When the function `multiply`that accesses memory is annotated `__declspec(noalias)`, it tells the compiler that this function does not modify the global state except through the pointers in its parameter list.
35
37
36
38
```C
37
39
// declspec_noalias.c
@@ -44,15 +46,15 @@ Decorating the function in the example that accesses memory with `__declspec(noa
0 commit comments