On 3/2/18 3:26 PM, Nordlöw wrote:
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote:
auto x = cast(Object)((cast(size_t *)null) + 1);
Is this preferred performance-wise over `cast(void*)(size_t.max)`?
No, it just works, as opposed to, um... not working ;)
I think the compiler senses you are trying to do something foolish (even
though that's not the case), and prevents you from doing it. For some
reason it doesn't care about it if it starts out as a pointer.
If both worked, or even cast(void *)(size_t.sizeof) worked, then the
performance would be the same, as you are casting a constant.
What you are looking for is a sentinel to check against. Either works
OK. As I said before, items in the zero page are not going to be mapped
by the OS. I'm not sure about size_t.max.