Hi,
The docs say:
when a number is comptime-known to be representable in
the destination type, it may be coerced.
What follows is an example
where u64 is initialized with 255, and then coerced to u8 simply by assignment.
So, I tried something similar, only between signed and unsigned:
const std = @import(“std”);
const expect = std.testing.expect;test “implicit unsigned integer to signed integer” {
var a: u8 = 2;
var b: i8 = a;
try expect(b == 2);
}
and the result was:
signed 8-bit int cannot represent all possible unsigned 8-bit values
Okay, I know that But I don’t have all possible unsigned 8-bit values, what I have takes
only 2 bits to represent.
So, a question:
What exactly does may (as in may be coerced) mean?
The way I see it, the problem with docs is that everything is written by somebody (and for somebody:)
who already knows how stuff works, and then can use it as a reminder, or a reference.
But learning anything from the docs in the current form is anything but easy. If Zig is announced as a simple language, I think it definitely needs clear documentation.
My take is that there are no simple languages. Many are too complicated, and some are trying
to be better. But simple? No, you can’t have anything simple when you are trying to make
something usable by humans, and machines still work as they always have.
But without clear, unambiguous docs, and with clear definitions for all important concepts, even relatively simple can turn out to be much harder than it needs to be.