#Zig assuming an integer literal (8) is a u3, and then erroring.

1 messages · Page 1 of 1 (latest)

tardy kettle
#
opcode = (memory[pc] << 8) | memory[pc + 1];

In this line, opcode is u16, memory is ([4096]u8), pc is u12.
Zig is giving me an error I can't make sense of:

src/chip8.zig:55:29: error: type 'u3' cannot represent integer value '8'
    opcode = (memory[pc] << 8) | memory[pc + 1];
                            ^

Why is this?

modern dove
#

youre not allowed to shift an int by more bits than it has and youre doing u8 << 8

#

(@as(u16, memory[pc]) << 8)

tardy kettle
#

Oh.. makes sense, but where does the u3 come from?

#

oh nvm

#

got it

proud sundial
#

or replace the whole thing with opcode = std.mem.readInt(u16, memory[pc..][0..2], .big)

modern dove
#

reads it as big endian