2 ms·
Rust does not have nulls beyond unsafe blocks, does it? >What makes it worse is that a null pointer in an option<> is handled as None instead of Some What? Ho
by ernst_klim 9y ago
Rust does not have nulls beyond unsafe blocks, does it?
>What makes it worse is that a null pointer in an option<> is handled as None instead of Some
What? How could NULL be treated as Some?
- steveklabnik 9y agoIt does not. I think your parent must have been doing something strange; if you have a *const T, one that's null will still be a Some. It's &T, which cannot be null by definition, that uses the null value as None, since it cannot be null.
- zaarn 9y agoI was actually using mut/const and got this bug, I don't think I used &T since I was handling raw memory addresses.
- steveklabnik 9y agoHm, then I don't know what happened, as I just checked and it's definitely not doing the optimization, as it shouldn't! If you can reproduce you should file a bug.
- zaarn 9y agoIt might help to know that I was writing an UEFI application, so basically kernel mode. Otherwise, I've redesigned the affected subsystem so I'm not sure I could reproduce the behaviour
- zaarn 9y agoNULL is still a valid memory address, which in this case I had to use. When packing such an address into a mut or const within a Option<>, a NULL will be treated like a None when you write, essentiall, Some(NULL).