=void in struct definition
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 9 13:42:04 UTC 2018
On 4/9/18 7:06 AM, Shachar Shemesh wrote:
> struct S {
> int a;
> int[5000] arr = void;
> }
>
> void func() {
> S s;
> }
>
> During the s initialization, the entire "S" area is initialized,
> including the member arr which we asked to be = void.
>
> Is this a bug?
Not technically. It has to initialize `a` to 0. The only way we
initialize structs is to copy the whole initializer with memcpy.
It would be possible to leave the "tail" uninitialized, and just store
the initializer for the first members that have non-void initializers.
But that's not how it works now.
If that were to happen, you'd still have the same issue with things like:
struct S {
int[5000] arr = void;
int a;
}
But maybe that's just something we would have to live with.
-Steve
More information about the Digitalmars-d
mailing list