Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Function

cTypeAlignment

Public Function
std.Target.cTypeAlignment
pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16

Returns null if no C ABI is defined for this target.

Params

File

Target.zig:3573
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
pub fn cTypeAlignment(target: *const Target, c_type: CType) ?u16 {
    // Overrides for unusual alignments
    switch (target.cpu.arch) {
        .avr,
        .ez80,
        .spork8,
        => return 1,
        .x86 => switch (target.os.tag) {
            .windows, .uefi => switch (c_type) {
                .longlong, .ulonglong, .double => return 8,
                .longdouble => switch (target.abi) {
                    .gnu => return 4,
                    else => return 8,
                },
                else => {},
            },
            else => {},
        },
        .m68k => switch (c_type) {
            .int, .uint, .long, .ulong => return 2,
            else => {},
        },
        .wasm32, .wasm64 => switch (target.os.tag) {
            .emscripten => switch (c_type) {
                .longdouble => return 8,
                else => {},
            },
            else => {},
        },
        else => {},
    }

    // Next-power-of-two-aligned, up to a maximum.
    return @min(
        std.math.ceilPowerOfTwoAssert(u16, ((cTypeBitSize(target, c_type) orelse return null) + 7) / 8),
        @as(u16, switch (target.cpu.arch) {
            .msp430,
            .x86_16,
            => 2,

            .arc,
            .arceb,
            .csky,
            .kalimba,
            .microblaze,
            .microblazeel,
            .or1k,
            .propeller,
            .sh,
            .sheb,
            .x86,
            .xcore,
            .xtensa,
            .xtensaeb,
            => 4,

            .amdgcn,
            .arm,
            .armeb,
            .bpfeb,
            .bpfel,
            .hexagon,
            .hppa,
            .lanai,
            .m68k,
            .m88k,
            .mips,
            .mipsel,
            .nvptx,
            .nvptx64,
            .s390x,
            .sparc,
            .thumb,
            .thumbeb,
            => 8,

            .aarch64,
            .aarch64_be,
            .alpha,
            .hppa64,
            .kvx,
            .loongarch32,
            .loongarch64,
            .mips64,
            .mips64el,
            .powerpc,
            .powerpcle,
            .powerpc64,
            .powerpc64le,
            .riscv32,
            .riscv32be,
            .riscv64,
            .riscv64be,
            .sparc64,
            .spirv32,
            .spirv64,
            .ve,
            .wasm32,
            .wasm64,
            .x86_64,
            => 16,

            .avr,
            .ez80,
            .spork8,
            => unreachable, // Handled above.
        }),
    );
}