How is this code invalid?
    thebluepandabear 
    therealbluepandabear at protonmail.com
       
    Sat Dec 17 00:23:32 UTC 2022
    
    
  
I am reading the fantastic book about D by Ali Çehreli, and he 
gives the following example when he talks about variadic 
functions:
```D
int[] numbersForLaterUse;
void foo(int[] numbers...) {
    numbersForLaterUse = numbers;
}
struct S {
   string[] namesForLaterUse;
   void foo(string[] names...) {
      namesForLaterUse = names;
   }
}
```
He says that the code above is a bug because:
"Both the free-standing function foo() and the member function 
S.foo() are in
error because they store slices to automatically-generated 
temporary arrays that
live on the program stack. Those arrays are valid only during the 
execution of the
variadic functions."
The thing is, when I run the code I get absolutely no error, so 
how is this exactly a 'bug' if the code runs properly? That's 
what I am confused about. What is the D compiler doing behind the 
scenes?
    
    
More information about the Digitalmars-d-learn
mailing list