| ▲ | TinkersW 5 hours ago |
| That is actually memory safe, as null will always trigger access violation.. Anyway safety checked modes are sufficient for many programs, this article claims otherwise but then contradicts itself by showing that they caught most issues using .. safety checked modes. |
|
| ▲ | steveklabnik 5 hours ago | parent | next [-] |
| It is undefined behavior. You cannot make a claim about what it will always do. |
|
| ▲ | maccard 5 hours ago | parent | prev | next [-] |
| >null will always trigger access violation.. No, it won't. https://gcc.godbolt.org/z/Mz8sqKvad |
| |
| ▲ | TinkersW 4 hours ago | parent [-] | | Oh my bad, I read that as nullptr, I use a custom optional that does not support such a silly mode as "disengaged" | | |
| ▲ | canyp 4 hours ago | parent | next [-] | | How is that an optional then? The problem is not nullopt, but that the client code can simply dereference the optional instead of being forced to pattern-match. And the next problem, like the other guy mentioned above, is that you cannot make any claims about what will happen when you do so because the standard just says "UB". Other languages like Haskell also have things like fromJust, but at least the behaviour is well-defined when the value is Nothing. | |
| ▲ | maccard 2 hours ago | parent | prev [-] | | What do you return if there is no value set? That’s the entire point of optional. |
|
|
|
| ▲ | wild_pointer 4 hours ago | parent | prev [-] |
| You didn't read this, did you?
https://alexgaynor.net/2019/apr/21/modern-c++-wont-save-us/ It's not a pointer. |