Re: bool passed by ref, safe or not ?

2024-06-06 Thread Quirin Schroll via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 18:31:12 UTC, Basile B. wrote: On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: ```d void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; setIt(*b);

Re: bool passed by ref, safe or not ?

2024-06-05 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: ```d void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; setIt(*b); assert(a == 0b); // what actually happens

Re: bool passed by ref, safe or not ?

2024-06-05 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 09:09:40 UTC, Kagamin wrote: On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: The only safe values for a `bool` are 0 (false) and 1 (true). AFAIK that was fixed and now full 8-bit range is safe. `cast(bool) someByte` is fine - that doesn't reinterpre

Re: bool passed by ref, safe or not ?

2024-06-05 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: The only safe values for a `bool` are 0 (false) and 1 (true). AFAIK that was fixed and now full 8-bit range is safe.

Re: bool passed by ref, safe or not ?

2024-06-05 Thread Dukc via Digitalmars-d-learn
Basile B. kirjoitti 4.6.2024 klo 19.58: 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 ? Viewing a valid boo

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Olivier Pisano via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 05:15:42 UTC, Olivier Pisano wrote: This is technically not a memory corruption, because as bool.sizeof < int.sizeof, you just write the low order byte of an int you allocated on the stack. It was not an int, it was a ushort. Anyway, what I wrote still applies.

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Olivier Pisano via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: question in the header, code in the body, execute on a X86 or X86_64 CPU 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 c

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: you have violated the language's safety invariants. ah mais non.

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: ```d void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; setIt(*b); assert(a == 0b); // what actually happens assert(a == 0b1110); // what would be safe } ```

Re: bool passed by ref, safe or not ?

2024-06-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: question in the header, code in the body, execute on a X86 or X86_64 CPU ```d module test; void setIt(ref bool b) @safe { b = false; } void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; s

Re: bool passed by ref, safe or not ?

2024-06-04 Thread rkompass via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: question in the header, code in the body, execute on a X86 or X86_64 CPU ```d module test; void setIt(ref bool b) @safe { b = false; } void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; s

bool passed by ref, safe or not ?

2024-06-04 Thread Basile B. via Digitalmars-d-learn
question in the header, code in the body, execute on a X86 or X86_64 CPU ```d module test; void setIt(ref bool b) @safe { b = false; } void main(string[] args) { ushort a = 0b; bool* b = cast(bool*)&a; setIt(*b); assert(a == 0b); // what actu