Repository navigation
Type Alias
Home › User Defined Types › Type (Alias)
Declares an alternative name for a type
Type typename As symboltypenamesymboltypename
symbol may refer to any declared data type including a built-in data type, Sub or Function pointer, Type declaration, Union declaration, or Enum declaration.
A Type Alias can be used to allow forward declarations of parameters in procedure declarations, but only used with pointers (whatever their passing mode), or otherwise with parameters (excluding arrays) but passed or returned only by reference. Generally the bodies of such procedures need to be implemented further in the code once the actual types are well defined (for example because of the passing of such a reference; or when such a pointer passed is then dereferenced in any form).
A Type Alias can also be used to allow forward declarations of data fields in User Defined Types, but only used with pointers.
A type alias must be used to allow declaration of pointer to a function pointer, otherwise ptr applies on return type and not on function.
A Type Alias declaration can also be nested inside a UDT structure declaration for a Type or aUnion.
- New to FreeBASIC
Type ParentFwd As Parent
Type Child
Name As ZString * 32
ParentRef As ParentFwd Ptr
''...
End Type
Type Parent
Name As ZString * 32
ChildList(0 To 9) As Child
''...
End Type
Dim p As Parent
p.Name = "Foo"
With p.ChildList(0)
.Name = "Jr."
.ParentRef = @p
'' ...
End With
With p.ChildList(0)
Print .Name; " is child of "; .parentRef->Name
End WithFunction triple (ByVal i As Integer) As Integer
Return 3 * i
End Function
Type As Function (ByVal As Integer) As Integer function_alias
'Dim As Function (Byval As Integer) As Integer f ''this syntax works but is less readable than the next code line
Dim As function_alias f
f = @triple
Print f(123)
'Dim As Function (Byval As Integer) As Integer Ptr pf ''this syntax does not work because Ptr applies on Integer and not on function
Dim As function_alias Ptr pf ''this syntax works
pf = @f
Print (*pf)(123) ''the dereferenced pointer to procedure pointer must be enclosed in parenthesesCategory: User Defined Types
Kind: alias
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.
- 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)
- 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