Partially initialized structs?

Arredondo arm.plus at gmail.com
Wed Feb 26 03:47:32 UTC 2025


Is it possible to declare a partially initialized struct?

I would have thought that doing it like this would work:

```
struct S {
     int[100] a = void;
     int b = 0;
}

```

But when I declare a variable of type `S`, the array `a` is 
initialized, so it seems that the `= void` is not playing any 
role here.

Of course `S s = void;` works for `a`, but then `b` is not 
initialized. I tried doing:

```
struct S {
	@disable this ();
	auto this(int b) {
		this.b = b;
		a = void;
	}
	
     int[100] a;
     int b = 0;
}
```
But that doesn't even compile.


I'm currently settling for something like:
```
auto placeS(string name)() => iq{
	S $(name) = void;
	$(name).b = 0;
}.text;
```
and then declare with `mixin(placeS!"s");`.

Is there a better way?

Cheers!
Arredondo.


More information about the Digitalmars-d-learn mailing list