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/coming-from-hlsl.md
+30
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,36 @@ int MyFunc()
75
75
}
76
76
```
77
77
78
+
#### Variable scope in `for`-loop follows the old FXC rule
79
+
The older version of HLSL compiler, FXC, had a little different variable scope for the `for`-loop compared to other languages.
80
+
81
+
FXC produces an error or a warning for the following code:
82
+
```
83
+
for (int i = 0; i < 4; i++) {...}
84
+
for (int i = 0; i < 4; i++) {...}
85
+
```
86
+
87
+
The warning looks like the following:
88
+
```
89
+
my_shader.hlsl(8,14): warning X3078: 'i': loop control variable conflicts with a previous declaration in the outer scope; most recent declaration will be used
90
+
```
91
+
92
+
This is no longer the case with the recent HLSL compiler, DXC. But Slang respects the old FXC rule and you may encounter an error like:
93
+
```
94
+
error 30200: declaration of 'i' conflicts with existing declaration
95
+
```
96
+
97
+
To resolve the problem, you can modify the shader to reuse the previously declared variable:
98
+
```
99
+
for (int i = 0; i < 4; i++) {...}
100
+
for (i = 0; i < 4; i++) {...} // Reuse the variable declared from the previous for-loop
101
+
```
102
+
103
+
Or, you can explicitly set the language to be `slang`:
0 commit comments