Repository navigation
Declare
Home › Procedures › Declare
Declares a module-level or member procedure
Declare Sub name [ param_list ]
Declare Function name [ param_list ] [ ByRef ] As return_type
Declare Operator op_symbol param_list [ [ ByRef ] As return_type ]
Type T
Declare Constructor [ param_list ]
Declare Destructor
Declare Sub name [ param_list ]
Declare Function name [ param_list ] [ ByRef ] As return_typeparam_listreturn_typenameop_symbolT
The Declare statement declares a Sub, Function, Operator, Constructor, or Destructor.
The procedure can be referred to in code without seeing its definition, although it must be defined somewhere. Essentially, the Declare statement introduces a procedure, and states that its definition is elsewhere. For example, a function can be declared at the top of a source module, called, then defined at the bottom of the source file, as shown below the example.
A procedure's declaration is almost identical to the first line of its definition, except the declaration is preceded by the Declare keyword and has no body. Also, attributes such as Export are left off the declaration.
FreeBASIC, as QB, does not require the declaration of the functions unless they are defined in a different source file or in the same file past the point where they are called. This is no longer true for procedures declared inside a Type body, which must always be declared first in the Type's body before use. If you do not declare Type procedures you will receive an error.
As every file using a function must have its declaration, declarations are usually kept in one or more include files to allow usage of the function by any module that needs it using the #include statement.
- In the -lang fb dialect,
ByValis the default parameter passing convention. In the -lang qb and -lang deprecated dialects,ByRefis the default parameter passing convention.
Type-levelSub/Function/Operator/Constructor/Destructor's are only allowed in -lang fb
- In FreeBASIC, the parameter names are optional.
SubFunctionOperatorPropertyConstructorDestructorConstructor (Module)Destructor (Module)TypeDimAlias (Name)Alias (Modifier)
Module-level Function:
'' declare the function sum which takes two integers and returns an integer
Declare Function sum( As Integer, As Integer ) As Integer
Print "the sum of 420 and 69 is: " & sum( 420, 69 ) '' call the function sum
'' define the function sum which takes two integers and returns an integer
Function sum( a As Integer, b As Integer ) As Integer
Return a + b
End FunctionType-level Sub:
Type my_type
my_data As Integer
Declare Sub increment_data( )
End Type
Sub my_type.increment_data( )
my_data += 1
End Sub
Dim As my_type an_instance
an_instance.my_data = 68
an_instance.increment_data( )
Print an_instance.my_dataCategory: Procedures
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing