Re: Validity of cast(void*)size_t.max

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/18 1:08 AM, Kagamin wrote: On Monday, 5 March 2018 at 18:28:43 UTC, Steven Schveighoffer wrote: Note, I think the error is bogus, you should be able to create hard-coded addresses of data at compile time -- I'm not sure how you would do hardware registers otherwise. I'd do them as exte

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Kagamin via Digitalmars-d-learn
On Monday, 5 March 2018 at 18:28:43 UTC, Steven Schveighoffer wrote: Note, I think the error is bogus, you should be able to create hard-coded addresses of data at compile time -- I'm not sure how you would do hardware registers otherwise. I'd do them as extern variables, it wouldn't be nice t

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 1:08 PM, Stefan Koch wrote: On Monday, 5 March 2018 at 18:04:20 UTC, Nordlöw wrote: On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-ti

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 5 March 2018 at 18:04:20 UTC, Nordlöw wrote: On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer?

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Monday, 5 March 2018 at 16:07:49 UTC, Steven Schveighoffer wrote: No, I mean you call holeKey at *runtime*. Inlined, it's just returning a constant, so it should reduce to a constant. A compile-time constant visible to the optimizer?

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 9:01 AM, Nordlöw wrote: On Monday, 5 March 2018 at 12:41:06 UTC, Steven Schveighoffer wrote: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } I still can't evaluate at compile-though...     enum holeKeyOffset = 0x1;

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Monday, 5 March 2018 at 12:41:06 UTC, Steven Schveighoffer wrote: pragma(inline, true) C lazyDeleted() pure nothrow @trusted { return cast(C)((cast(size_t*)null) + 1); } I still can't evaluate at compile-though... enum holeKeyOffset = 0x1; pragma(inline, true) stat

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/18 6:41 AM, 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); Thanks, how do I store it as enum or static immutable struct member? In @trusted pure unittest {     class C { int value; }     C x

Re: Validity of cast(void*)size_t.max

2018-03-05 Thread Nordlöw via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 20:07:50 UTC, Steven Schveighoffer wrote: auto x = cast(Object)((cast(size_t *)null) + 1); Thanks, how do I store it as enum or static immutable struct member? In @trusted pure unittest { class C { int value; } C x; C y = cast(C)((cast(size_t*)n

Re: Validity of cast(void*)size_t.max

2018-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
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 th

Re: Validity of cast(void*)size_t.max

2018-03-02 Thread Nordlöw via Digitalmars-d-learn
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)`?

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Ali Çehreli via Digitalmars-d-learn
On 02/28/2018 11:22 AM, Nordlöw wrote: On Tuesday, 27 February 2018 at 20:14:01 UTC, Ali Çehreli wrote: And to be sure, one can have an actual object that represents nullness and use its pointer. (Similar to "the null object pattern".) Ali Are there any pros to this pattern compared to just

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 19:22:12 UTC, Nordlöw wrote: Are there any pros to this pattern compared to just using `null` in D? When null is already used to mean something else.

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Kagamin via Digitalmars-d-learn
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 :)

Re: Validity of cast(void*)size_t.max

2018-02-28 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 20:14:01 UTC, Ali Çehreli wrote: And to be sure, one can have an actual object that represents nullness and use its pointer. (Similar to "the null object pattern".) Ali Are there any pros to this pattern compared to just using `null` in D?

Re: Validity of cast(void*)size_t.max

2018-02-27 Thread Ali Çehreli via Digitalmars-d-learn
On 02/27/2018 11:56 AM, Steven Schveighoffer wrote: On 2/27/18 11:37 AM, Nordlöw wrote: On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? It's already used to indicate that a slot is free. :) cast(void*)1 is likely to be unused. -Steve And to be

Re: Validity of cast(void*)size_t.max

2018-02-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/27/18 11:37 AM, Nordlöw wrote: On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? It's already used to indicate that a slot is free. :) cast(void*)1 is likely to be unused. -Steve

Re: Validity of cast(void*)size_t.max

2018-02-27 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:31:51 UTC, Steven Schveighoffer wrote: Why not use null? -Steve It's already used to indicate that a slot is free. :)

Re: Validity of cast(void*)size_t.max

2018-02-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/27/18 9:13 AM, Nordlöw wrote: Is `cast(void*)size_t.max` always an invalid address? You mean, can it point at valid data? Possibly, but likely not. In my past as an embedded developer, a lot of times the interrupt vectors are stored at the end of address space. Is so, could it be used

Validity of cast(void*)size_t.max

2018-02-27 Thread Nordlöw via Digitalmars-d-learn
Is `cast(void*)size_t.max` always an invalid address? Is so, could it be used to indicate removed/delete elements in hash tables with open addressing and a key type being either a pointer or class? And will it work correctly with the GC?