@daurnimator suggested leaving out the variable length arrays (VLAs) from some of our NT definitions; for example, we currently have something like this:
pub const FILE_NAME_INFORMATION = extern struct {
FileNameLength: ULONG,
FileName: [1]WCHAR,
};
where FileName is effectively a VLA which cannot be known a priori. The idea here is to weed that out leaving only the static elements, so in the above example, leaving in only FileNameLength. FileName VLA can then be accessed by taking a pointer just behind this static structure.
For the record: PR where this discussion originated #5993.
I think it would be reasonable to include a getter function in structs that use VLAs:
pub const FILE_NAME_INFORMATION = extern struct {
FileNameLength: ULONG,
pub fn getFileName(self: *@This()) []WCHAR {
return @intToPtr([*]WCHAR, @ptrToInt(self) + @sizeOf(ULONG))[0..self.FileNameLength];
}
};
I think it would be reasonable to include a getter function in structs that use VLAs:
pub const FILE_NAME_INFORMATION = extern struct { FileNameLength: ULONG, pub fn getFileName(self: *@This()) []WCHAR { return @intToPtr([*]WCHAR, @ptrToInt(self) + @sizeOf(ULONG))[0..self.FileNameLength]; } };
That's a cool idea, I like it!
I think it would be reasonable to include a getter function in structs that use VLAs:
Note that I've hit zig bugs doing this in the past.
might be fixed now though
I think it would be reasonable to include a getter function in structs that use VLAs:
Note that I've hit zig bugs doing this in the past.
- #2431 (comment)
- #4016
- other issues I can't find right now :(
might be fixed now though
Thanks for the heads up @daurnimator!
Most helpful comment
I think it would be reasonable to include a getter function in structs that use VLAs: