Repository navigation
Literals
Home › Literals
Non-variable compile-time string, numeric values and boolean values.
Literals are numbers, strings of characters or boolean truths specified directly in the source code. Literal values may be used by assigning them to a variable or constant, passing them to a procedure, or using them in an expression.
Numeric literals come in two forms - integer and floating-point.
Integer Literals
Decimal
Decimal digits ( 0 1 2 3 4 5 6 7 8 9 ).
Note: to get negative values, a "-" sign (Operator - (Negate)) can be placed before a numeric literal
Dim x As Integer = 123456
Dim b As Byte = -128Hexadecimal
"&H", followed by hexadecimal digits ( 0 1 2 3 4 5 6 7 8 9 A B C D E F ).
Dim x As Integer = &h1E240
Dim b As Byte = &H80Octal
"&O" (or "&"), followed by octal digits ( 0 1 2 3 4 5 6 7 )
Dim x As Integer = &O361100
Dim b As Byte = &O200Binary
"&B", followed by binary digits ( 0 1 )
Dim x As Integer = &B11110001001000000
Dim b As Byte = &B10000000Integer size suffixes
If an integer literal suffix is not given, the number field size required to hold the literal is automatically calculated. Specifying a size suffix guarantees that the compiler will consider a number as a specific integer size.
Integer literals ending with:
- "
%", are considered as signed 32/64 (depending on platform) bit integers. (Integer) - "
L", "&", are considered as signed 32 bit long integers. (Long) - "
U", are considered as unsigned 32/64 (depending on platform) bit integers. (UInteger) - "
UL", are considered as unsigned 32 bit integers. (ULong) - "
LL", are considered as signed 64 bit integers. (LongInt) - "
ULL", are considered as unsigned 64 bit integers. (ULongInt)
Negative (-) and positive (+) signs that prefix a numeric literal, are not part of the numeric literal. expressions (like "-1L") are parsed as the negate operator applied to the value represented by the positive literal ("1L"), which may involve implicit type conversions. Same behavior when an explicit "+" sign precedes the integer literal.
The prefixes, suffixes, and hexadecimal letter digits are all case-insensitive.
Dim a As Long = 123L
Dim b As UInteger = &h1234u
Dim c As LongInt = 76543LL
Dim d As ULongInt = &b1010101ULLFloating Point Literals
Floating point numbers are specified in decimal digits, may be positive or negative, have a fractional portion, and optionally an exponent. The format of a floating point literal is as follows (without space or parenthesis added):
number[.[fraction]][(D|E)[+|-][exponent]][suffix]
or
.fraction[(D|E)[+|-][exponent]][suffix]
By default, floating point numbers that do not have either an exponent or a suffix are considered as a double precision floating point value, except in the -lang qb dialect, where numbers of 7 digits or fewer are considered to be single precision.
Dim a As Double = 123.456
Dim b As Double = -123.0The letter "D" or "E", placed after the number/fraction part, allows the number to be given an exponent. The exponent may be specified as either positive or negative with a plus ("+") or minus ("-") sign. Exponents that do not have a sign are positive.
An exponent value is not required after the letter (or even after the sign), so the letter can be used on its own just to specify the type. "D" specifies a double-precision floating-point number. "E" specifies a floating-point number using the default precision. When the letter is used on its own in combination with a suffix (see below) the type denoted by the suffix overrules the type specified by the letter.
Dim a As Double = -123.0d
Dim b As Double = -123e
Dim c As Double = 743.1e+13
Dim d As Double = 743.1D-13
Dim e As Double = 743.1E13
Dim f As Single = 743D!A suffix of "!" or "F" on a number specifies a single precision (32 bit total) floating point value. A suffix of "#" or "D" specifies a double precision float.
Note that the letter suffixes and exponent specifiers are all case-insensitive.
Dim a As Single = 3.1!
Dim b As Single = -123.456e-7f
Dim c As Double = 0#
Dim d As Double = 3.141592653589e3#String Literals
String literals are a sequence of characters contained between two double quotes. The sequence of characters escaped or non-escaped.
Double quotes can be specified in the string literal by using two double quotes together.
Print "Hello World!"
Print "That's right!"
Print "See the ""word"" contained in double quotes."String literals can contain escape sequences if the string literal is prefixed by the ! Operator (Escaped String Literal). See Escape Sequences for a list of accepted escape sequences.
Print !"Hello\nWorld!"
By default, string literals are non-escaped unless Option Escape was used in the source in which case all string literals following are by default escaped.
A string may be explicitly specified as non-escaped when prefixed by the $ Operator (Non-Escaped String Literal).
Print $"C:\temp"
tiko: a string that spans several lines is written as a block string: """ at the end of a line opens it, and a line starting with """ closes it.
Besides ASCII files with Unicode escape sequences (\u), FreeBASIC can parse UTF-8, UTF-16LE, UTF-16BE, UTF-32LE and UTF-32BE source files as long as they were saved with Byte Order Mark (BOM), allowing unicode characters directly in the string literal.
Note: The most reliable cross-platform code is obtained by encoding without BOM in ASCII/UTF-8 characters.
String literals in an ASCII file are treated as ZString, while string literals in a Unicode file are treated as WString (regardless of the string literal's value).
Boolean Literals
The boolean type has two values, represented by literals True and False.
Dim a As Boolean = False
Dim b As Boolean = TrueSee also
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