question in the header, code in the body, execute on a X86 or X86_64 CPU
module test;
void setIt(ref bool b) @safe
{
b = false;
}
void main(string[] args)
{
ushort a = 0b1111111111111111;
bool* b = cast(bool*)&a;
setIt(*b);
assert(a == 0b1111111100000000); // what actually happens
assert(a == 0b1111111111111110); // what would be safe
}
I understand that the notion of bool
doesn't exist on X86, hence what will be used is rather an instruction that write on the lower 8 bits, but with a 7 bits corruption.
Do I corrupt memory here or not ?
Is that a safety violation ?