digitalmars.D.learn - Can't cast from void*
- Kagamin (7/7) Feb 03 2018 ---
- Steven Schveighoffer (8/16) Feb 05 2018 Superficially, it looks like it should work, given the previous 2 lines.
- Kagamin (6/7) Feb 06 2018 Maybe for least surprise. The error message almost convinced me
- Steven Schveighoffer (23/29) Feb 06 2018 Honestly, I don't know why it's not working. But maybe there is a reason...
- Temtaime (2/9) Feb 06 2018 Fill a bugreport.
--- interface A{} void* a=cast(void*)5; A b=cast(A)a; //ok A c=cast(A)cast(void*)5; //error --- Last line gives Error: cannot cast `void*` to `A`. Is it intended?
Feb 03 2018
On 2/3/18 12:37 PM, Kagamin wrote:--- interface A{} void* a=cast(void*)5; A b=cast(A)a; //ok A c=cast(A)cast(void*)5; //error --- Last line gives Error: cannot cast `void*` to `A`. Is it intended?Superficially, it looks like it should work, given the previous 2 lines. But I don't know what the compiler does to convince itself your code is wrong when you do it all in one expression. Is there a more pragmatic use case why this should be possible? It would help give motivation for fixing the problem. Clearly, `5` isn't going to be a valid interface pointer. -Steve
Feb 05 2018
On Monday, 5 February 2018 at 15:33:02 UTC, Steven Schveighoffer wrote:Is there a more pragmatic use case why this should be possible?Maybe for least surprise. The error message almost convinced me that such cast is impossible, only because of my memory that this cast used to be possible kept me trying. Is 5 not good because it's not big enough?
Feb 06 2018
On 2/6/18 3:29 AM, Kagamin wrote:On Monday, 5 February 2018 at 15:33:02 UTC, Steven Schveighoffer wrote:Honestly, I don't know why it's not working. But maybe there is a reason (i.e. it's not a bug and was done on purpose). All I meant is that, if you have a more practical correct reason for casting an integer literal to an interface, then we can show that it's worth worrying about. By illustration of what I'm talking about, D complains about this: int * foo() { int x; return &x; } But not this: int * bar() { int x; int *p = &x; return p; } Complaining about not being able to cast 5 directly to an interface, when you can do it in 2 statements, may be like complaining that bar compiles, why not foo? -SteveIs there a more pragmatic use case why this should be possible?Maybe for least surprise. The error message almost convinced me that such cast is impossible, only because of my memory that this cast used to be possible kept me trying. Is 5 not good because it's not big enough?
Feb 06 2018
On Tuesday, 6 February 2018 at 08:29:05 UTC, Kagamin wrote:On Monday, 5 February 2018 at 15:33:02 UTC, Steven Schveighoffer wrote:Fill a bugreport.Is there a more pragmatic use case why this should be possible?Maybe for least surprise. The error message almost convinced me that such cast is impossible, only because of my memory that this cast used to be possible kept me trying. Is 5 not good because it's not big enough?
Feb 06 2018