summaryrefslogtreecommitdiffstats
path: root/docs/user-guide
diff options
context:
space:
mode:
authorŠimon <95319163+wpsimon09@users.noreply.github.com>2025-07-23 05:10:25 +0200
committerGitHub <noreply@github.com>2025-07-23 03:10:25 +0000
commit387ba5b35fe0e3382b9cc043a007eefcca8ca121 (patch)
tree8cfe280df83ec303c0aac18f9018c0bce7f8cf8d /docs/user-guide
parent165a95ebb2e9dbdc1b92bdc103470438a5114500 (diff)
Added small section about default values of `struct` members (#7844)
* Added small section about default values of `struct` members * Added one more example and made `int a` to be brace initilised as well * Implemented suggested changes * Update docs/user-guide/02-conventional-features.md Co-authored-by: Yong He <yonghe@outlook.com> --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'docs/user-guide')
-rw-r--r--docs/user-guide/02-conventional-features.md19
1 files changed, 17 insertions, 2 deletions
diff --git a/docs/user-guide/02-conventional-features.md b/docs/user-guide/02-conventional-features.md
index 21387af3e..2571712ee 100644
--- a/docs/user-guide/02-conventional-features.md
+++ b/docs/user-guide/02-conventional-features.md
@@ -208,8 +208,23 @@ void test()
}
```
-> #### Note ####
-> Slang currently does not allow default values on struct members, but we intend to support them in the future.
+### Default Values for Struct Members
+
+Alternatively, you can specify default values of members in the struct like so:
+
+```hlsl
+struct MyData
+{
+ int a = 1;
+ float3 b = float3(0.5);
+}
+void test()
+{
+ MyData data = {}; // will initialize data.a to 1 and data.b to {0.5, 0.5, 0.5}
+ MyData data2 = MyData(); // equivalent to MyData data2 = {};
+ MyData data3; // data3.a and data3.b will be undefined !
+}
+```
### Enumeration Types