Change some keywords and enum manifests?
bearophile
bearophileHUGS at lycos.com
Tue Apr 27 17:10:59 PDT 2010
Aziz K.:
> I don't see what it has to do with OPTLINK.
With a smart compiler+linker there is no need to tell apart the two cases:
enum int x = 10;
immutable int y = 20;
If the linker is smart it can replace the references to y with 20 and then remove all the y name from the binary, just like for the x case. With LTO the LDC compiler is able to do this (but it's a D1 compiler, so there is only const, that equals to D2 enum).
On the other hand in a case like this dmd evaluates foo() only for the x case, so currently the enum semantics can not be fully replaced by immutable:
import std.c.stdio: printf;
int foo(int n) {
int tot;
foreach (i; 0 .. n)
tot += i;
return tot;
}
void main() {
enum int x = foo(10);
printf("%d\n", x);
immutable int y = foo(20);
printf("%d\n", y);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list