Skip to content

Double star array initialization syntax not working #20930

@nock24

Description

@nock24

Zig Version

0.13

Steps to Reproduce and Observed Behavior

I'm writing bare metal code for the raspberry pi 3b and when using the double star initialization syntax it seems to get stuck in an endless loop and all code after it being used doesn't run. Using @memset() works as expected

export fn kernel_main() noreturn {
    var buf = [_]u8{0} ** 10;
    buf[0] = 1;

    serial.init();
    serial.writeStr("Hello\n"); // this never runs

    while (true) {}
}

In this other case it seems like I get the same issue but instead with @memset.

serial.writeStr("debug1"); // this gets printed
var cmd_name_buf: [MAX_CMD_NAME_LEN]u8 = undefined;
@memset(&cmd_name_buf, 0);
serial.writeStr("debug2"); // this doesn't
var cmd_name_len: usize = undefined;

for (str, 0..) |char, i| {
    if (char == ' ' or i == str.len - 1) { // end of command
        cmd_name_len = i;
        break;
    }

    if (i >= MAX_CMD_NAME_LEN) return CmdParseError.InvalidCmd;
    cmd_name_buf[i] = char;
}

const cmd_name = cmd_name_buf[0..cmd_name_len];
const args_str = str[cmd_name_len + 1 ..];

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions