08 April 2020, 16:30 | #1 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
Forward statement or function
I just start using statements/functions.
(f.e. to write a small function to calculate "atan2") From all info I found and all I tried the function has to be written above the function call in the code, to be found. Is it possible to forward functions and statements (so they are found even at the end of the code)? |
09 April 2020, 01:42 | #2 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,214
|
Define them in a separate file and include them at the top of your main file
|
09 April 2020, 03:09 | #3 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
Yes, that was my PlanB too.
A pity there's no "forward". Thanks E-Penguin, stay safe! |
09 April 2020, 11:55 | #4 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,245
|
Quote:
Code:
int foo(int arg1,double arg2); ... int bar(..) { foo(1,42.0); /* use foo */ } ... int foo(int arg1,double arg2) { /* implement foo */ } |
|
09 April 2020, 16:27 | #5 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,364
|
Unfortunately, the Blitz compiler doesn't support this prototype concept that C uses. Only one function declaration is allowed throughout the code, and it must be declared before it is called. Which can be a pain when you have lots of functions calling other functions...
For bigger projects, I tend to keep functions in a separate file as suggested and include it near the top of the main source file. Alternatively, if you want to keep the definitions in the main file, you can add labels to the code so it's easy to skip past the function declarations. For example: Code:
Function MyFunc.b{var.w} [...] End Function ; *** Start of main code .maincode [...] Main loop here Last edited by Daedalus; 17 April 2020 at 13:46. |
17 April 2020, 01:02 | #6 |
Registered User
Join Date: Mar 2018
Location: Austria
Posts: 617
|
Sorry for the late answer but real life (and Revision) got in the way.
I was asking mainly because I was surprised because contrary to functions, "Gosub" finds subroutines no matter where they are. Guess that's one of the reasons why Gosub is more often used Anyway, just checked out INCLUDE and XINCLUDE. They work nicely, so that's a good possibility to include statements/functions. Thanks for the clarification! |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
for..each statement in CLI | pieter1976 | support.Other | 10 | 09 January 2020 22:15 |
Share NewType to Statement/Function | earok | Coders. Blitz Basic | 21 | 30 May 2018 13:37 |
AmigaOS 3.1 source code leak - official statement | Cyborg | News | 71 | 09 January 2016 09:08 |
SECTION statement and the CHIP/FAST attribute | Apollo | Coders. Asm / Hardware | 3 | 15 June 2013 18:18 |
Hyperion Statement on litigation with Amiga Inc. | Ultron | News | 2 | 02 May 2007 11:06 |
|
|