Re: How is this code invalid?

2022-12-17 Thread j via Digitalmars-d-learn
On Saturday, 17 December 2022 at 00:23:32 UTC, thebluepandabear wrote: 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 =

Re: How is this code invalid?

2022-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 17, 2022 at 02:36:10AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > Thanks, I've tried to mark it with `@safe` and it did give me a > warning. > > I was also wondering, why is this code valid? > > ```D > int[] numbersForLaterUse; > > @safe void foo(int[] numbers)

Re: How is this code invalid?

2022-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/16/22 18:20, H. S. Teoh wrote: > scratch space for computations, called the runtime > stack. I called it "function call stack" where I gave a very simplistic view of it here: https://www.youtube.com/watch?v=NWIU5wn1F1I=236s > (2) Use @safe when possible so that the compiler will

Re: How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
T Thanks, I've tried to mark it with `@safe` and it did give me a warning. I was also wondering, why is this code valid? ```D int[] numbersForLaterUse; @safe void foo(int[] numbers) { numbersForLaterUse = numbers; } ```

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 16, 2022 at 05:39:08PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > If you really want to see what could possibly have gone wrong, try > this version of the code: [...] > The results will likely differ depending on your OS and specific > environment; but on my Linux

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 17, 2022 at 12:23:32AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > ```D > int[] numbersForLaterUse; > > void foo(int[] numbers...) { >numbersForLaterUse = numbers; > } > > struct S { > string[] namesForLaterUse; > > void foo(string[] names...) { >

Re: How is this code invalid?

2022-12-16 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 17 December 2022 at 00:23:32 UTC, thebluepandabear wrote: ```D int[] numbersForLaterUse; void foo(int[] numbers...) { numbersForLaterUse = numbers; } struct S { string[] namesForLaterUse; void foo(string[] names...) { namesForLaterUse = names; } } ``` [...] The

How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
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[]