When D feels unfinished: union initialization and NRVO
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Mar 19 18:46:13 UTC 2020
On Thu, Mar 19, 2020 at 06:28:17PM +0000, Kagamin via Digitalmars-d wrote:
> As I understand, the problem is that switch statement was taken from C
> where it's a goto with a bunch of labels, so the compiler can't easily
> reason about variable lifetime or something like that.
In D, this code (Duff's device) compiles:
int i = 0, j = 0;
switch (i % 4) {
while (i < 10) {
case 0: j++; goto case 1;
case 1: j++; goto case 2;
case 2: j++; goto case 3;
case 3: default: j++;
}
}
Lifetime analysis is either going to break down or become seriously
convoluted, if you try to apply it here!
T
--
Don't throw out the baby with the bathwater. Use your hands...
More information about the Digitalmars-d
mailing list