On Tuesday, 13 September 2022 at 09:57:38 UTC, Dennis wrote:
On Tuesday, 13 September 2022 at 09:43:46 UTC, test123 wrote:
This will not work since the C have no array like D.

You can use a 0-size static array:
```D
struct mystruct {
uint32_t mask_limit; // Limit enum value that can be tested with mask.
        uint32_t value_count;  // Number of values after the bitfield.
        uint32_t[0] data;      // Bitmask + enumerated values follow.
}
```

Then you have to index with `mystructVar.data.ptr[i]` to avoid bounds checking.

Thanks, this look nice.

What I need is init the const object at CTFE.

I try this way:

```d
struct validate_KnownRegex_enum_init_type { const upb_MiniTable_Enum header; uint[2] data; } __gshared const validate_KnownRegex_enum_init_type validate_KnownRegex_enum_init = { {64, 2}, [7, 0] };
```

The problem is I can not assign it into one array (give error):

```d
__gshared const test = cast(upb_MiniTable_Enum*) &validate_KnownRegex_enum_init;
    __gshared const __enums_layout = [
        test,
    ];
```

This will also not work:

```d
    __gshared const upb_MiniTable_Enum*[1] __enums_layout = [
        &validate_KnownRegex_enum_init.header,
    ];
```

Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ?

Reply via email to