English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 08 April 2020, 16:30   #1
Nightshft
Registered User
 
Nightshft's Avatar
 
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)?
Nightshft is offline  
Old 09 April 2020, 01:42   #2
E-Penguin
Banana
 
E-Penguin's Avatar
 
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
E-Penguin is offline  
Old 09 April 2020, 03:09   #3
Nightshft
Registered User
 
Nightshft's Avatar
 
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!
Nightshft is offline  
Old 09 April 2020, 11:55   #4
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,245
Quote:
Originally Posted by Nightshft View Post
Is it possible to forward functions and statements (so they are found even at the end of the code)?
Yes, of course. That's a "prototype". For that, just write the function header, but omit the body of the function:
Code:
 int foo(int arg1,double arg2); ... int bar(..) {  foo(1,42.0); /* use foo */ } ... int foo(int arg1,double arg2) { /* implement foo */ }
Thomas Richter is offline  
Old 09 April 2020, 16:27   #5
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,364
Quote:
Originally Posted by Thomas Richter View Post
Yes, of course. That's a "prototype".
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
Putting the dot in front of the maincode label here makes it show up in the navigation pane to the right of the code editor. You can then click on it to jump the editor directly to that point instead of scrolling through.

Last edited by Daedalus; 17 April 2020 at 13:46.
Daedalus is offline  
Old 17 April 2020, 01:02   #6
Nightshft
Registered User
 
Nightshft's Avatar
 
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!
Nightshft is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:12.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07460 seconds with 15 queries