Re: Forward referencing functions in D

2020-10-17 Thread Ali Çehreli via Digitalmars-d-learn
On 10/17/20 8:28 AM, NonNull wrote: On Friday, 16 October 2020 at 21:28:18 UTC, Steven Schveighoffer wrote: Inner functions have benefits: 1. They are only accessible inside the function. Which means you only have to worry about correctness while INSIDE that function. 2. inner functions have

Re: Forward referencing functions in D

2020-10-17 Thread NonNull via Digitalmars-d-learn
On Friday, 16 October 2020 at 21:28:18 UTC, Steven Schveighoffer wrote: Inner functions have benefits: 1. They are only accessible inside the function. Which means you only have to worry about correctness while INSIDE that function. 2. inner functions have access to the outer function's stack

Re: Forward referencing functions in D

2020-10-16 Thread wilcro via Digitalmars-d-learn
On Friday, 16 October 2020 at 19:55:53 UTC, wilcro wrote: The web page "Programming in D for C Programmers" (https://dlang.org/articles/ctod.html#forwardfunc) states that forward declarations are neither required nor permitted, and that the following construct is allowable: void myfunc() {

Re: Forward referencing functions in D

2020-10-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/16/20 4:47 PM, wilcro wrote: Thanks to all for your responses; as a related followup question, would there be any reason to avoid placing the majority of code for a program outside of the main function? Inner functions have benefits: 1. They are only accessible inside the function.

Re: Forward referencing functions in D

2020-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/20 1:47 PM, wilcro wrote: > would > there be any reason to avoid placing the majority of code for a program > outside of the main function? Keeping scopes of symbols as small as possible is a general guideline in D and elsewhere but I wouldn't crowd my main() function with details of

Re: Forward referencing functions in D

2020-10-16 Thread wilcro via Digitalmars-d-learn
On Friday, 16 October 2020 at 19:55:53 UTC, wilcro wrote: The web page "Programming in D for C Programmers" (https://dlang.org/articles/ctod.html#forwardfunc) states that forward declarations are neither required nor permitted, and that the following construct is allowable: void myfunc() {

Re: Forward referencing functions in D

2020-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 16, 2020 at 08:04:07PM +, Imperatorn via Digitalmars-d-learn wrote: [...] > I think it might be just because you havent defined the function yet > at that point. That's not correct; the following works: module mymodule; void func() {

Re: Forward referencing functions in D

2020-10-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 16, 2020 at 07:55:53PM +, wilcro via Digitalmars-d-learn wrote: > The web page "Programming in D for C Programmers" > (https://dlang.org/articles/ctod.html#forwardfunc) states that forward > declarations are neither required nor permitted, [...] > However, the following code will

Re: Forward referencing functions in D

2020-10-16 Thread Imperatorn via Digitalmars-d-learn
On Friday, 16 October 2020 at 19:55:53 UTC, wilcro wrote: The web page "Programming in D for C Programmers" (https://dlang.org/articles/ctod.html#forwardfunc) states that forward declarations are neither required nor permitted, and that the following construct is allowable: void myfunc() {

Re: Forward referencing functions in D

2020-10-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 16 October 2020 at 19:55:53 UTC, wilcro wrote: Evidently, I am misunderstanding something very elemental here; thanks for any enlightenment regarding this. Inside a function things happen in order, top to bottom, including declarations (you can only access local variables after