No, stack allocation should not destroyed
Hipreme
msnmancini at hotmail.com
Tue Jul 19 11:00:58 UTC 2022
On Monday, 18 July 2022 at 18:01:45 UTC, Ola Fosheim Grøstad
wrote:
> On Monday, 18 July 2022 at 17:45:08 UTC, FeepingCreature wrote:
>> Spurious compiler errors, fine, but a compiler update should
>> not cause a very basic construct like [] to start corrupting
>> values.
>
> But this is more of a development process and quality assurance
> issue than a language design issue.
>
> The former should adapt to the latter, not the other way around…
I have made a Renderer abstraction, so, in OpenGL terms I have
been setting my Uniform variables such as `Vector2`, `Vector3`,
`Vector4`. But importing `math.vector` for just setting those
variables creates unnecessary dependency, what have I done to
solve this problem?
```d
void setUniform(string uniformName, float[2] vec);
void setUniform(string uniformName, float[3] vec);
void setUniform(string uniformName, float[4] vec);
```
What happens if I do:
```d
void setupRenderer() @nogc
{
setUniform("Test", [1, 2]);
setUniform("Test", [1, 2, 3]);
setUniform("Test", [1, 2, 3, 4]);
}
```
Then what it happens?
Error: `@nogc` function `setupRenderer` cannot call non- at nogc
function `renderer.setUniform`
Error: `@nogc` function `setupRenderer` cannot call non- at nogc
function `renderer.setUniform`
Error: `@nogc` function `setupRenderer` cannot call non- at nogc
function `renderer.setUniform`
You guys solution:
```d
import std.array;
void setupRenderer() @nogc
{
setUniform("Test", [1, 2].staticArray);
setUniform("Test", [1, 2, 3].staticArray);
setUniform("Test", [1, 2, 3, 4].staticArray);
}
```
Unnecessary verbosity. That's all I could say. Then, what happens?
```
onlineapp.d(29): Error: none of the overloads of `setUniform` are
callable using argument types `(string, int[2])`
onlineapp.d(13): Candidates are:
`onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17):
`onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21):
`onlineapp.setUniform(string uniformName, float[4] vec)`
onlineapp.d(30): Error: none of the overloads of `setUniform` are
callable using argument types `(string, int[3])`
onlineapp.d(13): Candidates are:
`onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17):
`onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21):
`onlineapp.setUniform(string uniformName, float[4] vec)`
onlineapp.d(31): Error: none of the overloads of `setUniform` are
callable using argument types `(string, int[4])`
onlineapp.d(13): Candidates are:
`onlineapp.setUniform(string uniformName, float[2] vec)`
onlineapp.d(17):
`onlineapp.setUniform(string uniformName, float[3] vec)`
onlineapp.d(21):
```
So, for solving that, one must either:
`setUniform("Test", [cast(float)1, 2].staticArray);`
Or they need to actually have a float literal in the array.
Actually, I think that could be one of the the worse usecases for
that
More information about the Digitalmars-d
mailing list