array construction without heap alloc
    0ffh 
    frank at frankhirsch.youknow.what.todo.net
       
    Mon Dec 24 04:42:02 PST 2007
    
    
  
Jarrett Billingsley wrote:
> Before anyone says "but the compiler could detect those", what about in this 
> case:
> 
> extern(C) someFunc(int* arr, int len);
> 
> void myFunc(int x, int y)
> {
>     auto arr = [x, y];
>     someFunc(arr.ptr, arr.length);
> }
> 
> The compiler knows nothing about what someFunc does and can't tell if it 
> stores that array away in some global variable or something, therefore it 
> can't tell if this is legal code.  (This is why side effects are bad, the FP 
> programmers tell us..) 
If I am not mistaken, your example here does the "bad thing" already, no
matter if it allocates heap to initialise the variable or not.
regards, frank
    
    
More information about the Digitalmars-d-learn
mailing list