Repository navigation
Common
Home › Modularizing › Common
Variable declaration and scope modifier
Common [Shared] symbolname[()] [AS DataType] [, ...]Declares a variable which is shared between code modules, including those to be compiled as static and dynamic libraries (DLLs).
A matching Common statement must appear in all other code modules using the variable.
Common variables cannot be initialized.
Common arrays are always variable-length, and must be defined with an empty parameter list (), and its dimensions set in a later Dim or ReDim statement.
Common variables cannot be instances of a user-defined type having a constructor or a destructor even implicit.
The Shared optional parameter makes the variable global so that it can be used inside Subs and Functions, as well as at module level.
- Windows does not support
Commonwith a dynamic library (compiled with -dll or -dylib).
- The arrays will be always variable-length.
-
blocknameis not needed and must be removed because the order of declaration no longer matters, only the symbol names. -
Commondoes not allow to keep the values of certain variables when chaining programs withChain.
'' common1.bas
Declare Sub initme()
Common Shared foo() As Double
ReDim foo(0 To 2)
initme()
Print foo(0), foo(1), foo(2)'' common2.bas
Common Shared foo() As Double
Sub initme()
foo(0) = 4*Atn(1)
foo(1) = foo(0)/3
foo(2) = foo(1)*2
End SubAfter compiling the two files like:
fbc common1.bas common2.bas
running common1 produces the output:
3.141592653589793 1.047197551196598 2.094395102393195Category: Modularizing
Kind: keyword
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