int => struct cast

Jarrett Billingsley jarrett.billingsley at gmail.com
Thu Oct 2 07:25:03 PDT 2008


On Thu, Oct 2, 2008 at 10:04 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Why can't I cast  an n int to a struct with only a x int field?
> Time ago someone has said that all internal errors are problems, is this known and bad?
>
> struct S { int x; }
> void main() {
>    int n = 1;
>    int[S] a;
>    a[ cast(S)n ]++;
> }
>
> OUTPUT DMD 1.035:
> temp.d(5): Error: e2ir: cannot cast from int to S
> Internal error: e2ir.c 3904
>
> Bye,
> bearophile
>

I'm guessing you can't do it because it doesn't make any sense.  Since
when did you expect this to work?  The typical solution is to cast
through a pointer, i.e. "*cast(S*)&n".

And yes, any time you see "internal error" put.  it.  in.  bugzilla.  please.


More information about the Digitalmars-d-learn mailing list