Skip to content

Commit f3c398b

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#166 from manbearian/patch-2
Remove __declspec(restrict) from example
2 parents a5916b4 + 2faf0ea commit f3c398b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

docs/cpp/noalias.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "noalias | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "02/09/2018"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology: ["cpp-language"]
@@ -25,13 +25,15 @@ ms.workload: ["cplusplus"]
2525

2626
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).
2727

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).
2931

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
3133

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)`.
3335

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.
3537

3638
```C
3739
// declspec_noalias.c
@@ -44,15 +46,15 @@ Decorating the function in the example that accesses memory with `__declspec(noa
4446

4547
float * mempool, * memptr;
4648

47-
__declspec(restrict) float * ma(int size)
49+
float * ma(int size)
4850
{
4951
float * retval;
5052
retval = memptr;
5153
memptr += size;
5254
return retval;
5355
}
5456

55-
__declspec(restrict) float * init(int m, int n)
57+
float * init(int m, int n)
5658
{
5759
float * a;
5860
int i, j;
@@ -94,12 +96,13 @@ int main()
9496
a = init(M, N);
9597
b = init(N, P);
9698
c = init(M, P);
97-
99+
98100
multiply(a, b, c);
99101
}
100102
```
101103
102104
## See Also
103105
104106
[__declspec](../cpp/declspec.md)
105-
[Keywords](../cpp/keywords-cpp.md)
107+
[Keywords](../cpp/keywords-cpp.md)
108+
[__declspec(restrict)](../cpp/restrict.md)

0 commit comments

Comments
 (0)