Automatic void initialization

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Jun 2 07:01:37 PDT 2009


On Tue, Jun 2, 2009 at 8:10 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Walter Bright:
>>Dead assignment elimination is compiler technology from the 70's !<
>
> I'd like to see this technology used for arrays too. So in the following two adjacent lines of code "a" doesn't get initialized to zero before being initialized again to 5:
>
> void main() {
>    auto a = new int[10];
>    a[] = 5;
>    printf("%d\n", a[3]);
> }
>
> The ASM:
>
> sub ESP,01Ch
> mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
> push 0Ah
> push EAX
> call near ptr __d_newarrayT
> mov 0Ch[ESP],EAX
> mov 010h[ESP],EDX
> push dword ptr 0Ch[ESP]
> push 5
> push EDX
> mov 014h[ESP],EDX
> call near ptr __memset32
> mov ECX,014h[ESP]
> mov EDX,offset FLAT:_DATA
> push dword ptr 0Ch[ECX]
> push EDX
> call near ptr _printf
> [...]

As far as I know, LDC already does this.



More information about the Digitalmars-d mailing list