Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

headFieldAlignment

Look ahead through the fields of the record to determine what the alignment of the record would be without any align/packed/etc. attributes. This helps us determine whether or not the fields with 0 offset need an align qualifier. Strictly speaking, we could just pedantically assign those fields the same alignment as the parent's pointer alignment, but this helps the generated code to be a little less verbose.

Translator.headFieldAlignment
fn headFieldAlignment(t: *Translator, record_decl: aro.Type.Record) ?c_uint

File

lib/compiler/translate-c/Translator.zig:1319

Code

fn headFieldAlignment(t: *Translator, record_decl: aro.Type.Record) ?c_uint {
    const bits_per_byte = 8;
    const parent_ptr_alignment_bits = record_decl.layout.?.pointer_alignment_bits;
    const parent_ptr_alignment = parent_ptr_alignment_bits / bits_per_byte;
    var max_field_alignment_bits: u64 = 0;
    for (record_decl.fields) |field|
        max_field_alignment_bits = @max(max_field_alignment_bits, bits_per_byte * field.qt.alignof(t.comp));
    if (max_field_alignment_bits != parent_ptr_alignment_bits) {
        return parent_ptr_alignment;
    } else {
        return null;
    }
}