summaryrefslogtreecommitdiffstats
path: root/docs/user-guide
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-03-04 14:15:22 -0800
committerGitHub <noreply@github.com>2024-03-04 14:15:22 -0800
commit0371deef52c2ef9ffda3c5ec11f5b1082c0b96e8 (patch)
tree59d537a20ff1748771a68fefc87ef02ae4079e10 /docs/user-guide
parent01efe34dbef2be952298075abd8d36cc67ac9f4e (diff)
Add user-guide section on pointers. (#3670)
Diffstat (limited to 'docs/user-guide')
-rw-r--r--docs/user-guide/03-convenience-features.md15
-rw-r--r--docs/user-guide/toc.html1
2 files changed, 16 insertions, 0 deletions
diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md
index 948400731..ca4635df4 100644
--- a/docs/user-guide/03-convenience-features.md
+++ b/docs/user-guide/03-convenience-features.md
@@ -361,6 +361,21 @@ float4 myPackedVector = reinterpret<float4>(myVal);
`reinterpret` can pack any type into any other type as long as the target type is no smaller than the source type.
+## Pointers
+
+Slang supports pointers when generating code for SPIRV, C++ and CUDA targets. The syntax for pointers is similar to C, with the exception that operator `.` can also be used to dereference a member. Slang currently does not support the `->` operator.
+For example:
+```csharp
+int test(MyType* pObj)
+{
+ MyType* pNext = pObj + 1;
+ MyType* pNext = &pNext[1];
+ return pNext.a + (*pNext).a + pNext[0].a;
+}
+```
+
+Pointer types can also be specified using the generic syntax: `Ptr<MyType>` is equivalent to `MyType*`.
+
## `struct` inheritance (limited)
Slang supports a limited form of inheritance. A derived `struct` type has all the members defined in the base type it is inherited from:
diff --git a/docs/user-guide/toc.html b/docs/user-guide/toc.html
index c9aa4cafb..3564ccf69 100644
--- a/docs/user-guide/toc.html
+++ b/docs/user-guide/toc.html
@@ -40,6 +40,7 @@
<li data-link="convenience-features#subscript-operator"><span>Subscript Operator</span></li>
<li data-link="convenience-features#optionalt-type"><span>`Optional&lt;T&gt;` type</span></li>
<li data-link="convenience-features#reinterprett-operation"><span>`reinterpret&lt;T&gt;` operation</span></li>
+<li data-link="convenience-features#pointers"><span>Pointers</span></li>
<li data-link="convenience-features#struct-inheritance-limited"><span>`struct` inheritance (limited)</span></li>
<li data-link="convenience-features#extensions"><span>Extensions</span></li>
<li data-link="convenience-features#multi-level-break"><span>Multi-level break</span></li>