From 9553a7ce7b01ce0400bedbd38646e21e0f2fa4b7 Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Fri, 24 May 2024 11:24:53 -0400 Subject: Fix pointer example (#4224) * Fix pointer example Make the example shown for pointers something that would compile. Don't redefine pNext and do define MyType. * Fix formatting of struct in pointer example --- docs/user-guide/03-convenience-features.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md index 8954349f7..420db18c1 100644 --- a/docs/user-guide/03-convenience-features.md +++ b/docs/user-guide/03-convenience-features.md @@ -411,11 +411,16 @@ float4 myPackedVector = reinterpret(myVal); 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 from a pointer. For example: ```csharp +struct MyType +{ + int a; +}; + int test(MyType* pObj) { MyType* pNext = pObj + 1; - MyType* pNext = &pNext[1]; - return pNext.a + pNext->a + (*pNext).a + pNext[0].a; + MyType* pNext2 = &pNext[1]; + return pNext.a + pNext->a + (*pNext2).a + pNext2[0].a; } ``` -- cgit v1.2.3