Validity of cast(void*)size_t.max
Steven Schveighoffer
schveiguy at yahoo.com
Wed Feb 28 20:07:50 UTC 2018
On 2/28/18 3:00 PM, Kagamin wrote:
> On Tuesday, 27 February 2018 at 19:56:44 UTC, Steven Schveighoffer wrote:
>> cast(void*)1 is likely to be unused.
>
> And since there was a word about class, cast(Class)cast(void*)1 won't
> compile :)
Oh, and it has a horrible message! Says you can't cast void * to Class.
Which you can do, but apparently not if the compiler can tell if it's an
integer you are casting from.
This does work:
auto x = cast(Object)((cast(size_t *)null) + 1);
I used size_t instead of ubyte, because it will avoid any weird bus
errors on certain platforms. You'll just get a segfault.
-Steve
More information about the Digitalmars-d-learn
mailing list