No, stack allocation should not destroyed

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Jul 19 13:07:53 UTC 2022


On Tuesday, 19 July 2022 at 11:00:58 UTC, Hipreme wrote:
>
> ```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`

I don't understand the issue, this works?

```
import std;
float[2] a;
void setUniform(string uniformName, float[2] vec)@nogc { a = vec;}

void setupRenderer() @nogc
{
     setUniform("Test", [1, 2]);
}
void main()
{
    setupRenderer();
    writeln(a);
}
```



More information about the Digitalmars-d mailing list