#How to initialize an Array of Structs?

1 messages · Page 1 of 1 (latest)

topaz roost
#

I feel like I'm missing something obvious, but I can't seem to find an example of doing this anywhere...

const InsTabEntry = struct {
    mask: u32,
    bits: u32,
    fmt: []const u8,
};

const instab : [_]InsTabEntry = .{
    { .mask = 0x0000707f, .bits = 0x00004013, .fmt = "xori %d, %1, %i", },
    // ...
};

This doesn't compile... and I've tried a number of variations and have not landed on anything that appears to get me an array of InsTabEntry structs.

timid mirage
#

[_] isn't valid as part of a type

#

if you change that to const instab = [_]InsTabEntry{...}; it should work fine

#

essentially, [_]T is only valid as a prefix to an array literal; the type has to be a specific type [n]T always