Repository navigation
Zstring
Home › Standard Data Types › ZString
Standard data type: 8 bit character string
Dim variable As ZString * size
Dim variable As ZString PtrA ZString is a C-style fixed-size array of chars. It has no descriptor so its length is calculated faster to pass it as an argument to functions. When the variable has a fixed size (numeric constant, or expression that can be evaluated at compile time), FreeBASIC avoids any overflow that could occur on assignment, by truncating the contents to a length of size - 1.
A ZString Ptr can point to a standard ZString, also can be used to implement an "user-managed" ZString, in this case Allocate/Reallocate/Deallocate must be used to size-resize-dispose it and is up to the user to avoid overflows .
The end of the string is marked by a null character (0 ASCII). This is automatically added by the FreeBASIC string handling functions. A null character will be appended when the string is created, and the length will be calculated by scanning the string for the first null character. A null character (e.g. Chr(0)) may never be contained in the text of a ZString or the rest of the string will be truncated.
In a ZString, Len returns the size of the contained string and SizeOf returns the space allocated to the ZString. SizeOf only works if the size is known by the compiler, i.e. a fixed-size ZString variable is passed directly, not as a dereferenced pointer or a ByRef function argument.
Any intrinsic string functions like Left will work with ZString's too, plus any string operator.
This type is provided for easy interfacing with C libraries and to also replace the fixed-length strings, that can't be managed through pointers.
Any string type argument may be directly passed to a procedure referring to a parameter declared as ZString Ptr. The compiler performs itself an automatic conversion (without warning message) between any string type argument and the ZString Ptr type parameter.
When allocating dynamic memory for a ZString, the safest is to use CAllocate (or at worst, to use Allocate followed by an immediate assignment of the string data, as in the second example), in order to avoid creating string data without any null character (the terminal character for a ZString).
Note : When any operand of a binary operator (as assignment, equal, +, *, ...) consists in dereferencing a 'Zstring Ptr' pointer ('pz'), this can give a 'Zstring' string or a 'Ubyte' variable, depending on the other operand. If the other operand is numeric, so the dereferenced 'Zstring Ptr' pointer ('*pz') will be treated as a 'Ubyte' reference to the one character pointed. If a 'Zstring' pointer indexing '[]' operator is used as dereferencing syntax ('pz[n]'), it is basically a short-cut version of the 'String' indexing '[]' operator ('(*pz)[n]').
- Not available in the -lang qb dialect unless referenced with the alias
__Zstring.
- New to FreeBASIC
Dim As ZString * 13 str1 => "hello, world"
Print str1
Print Len(str1) 'returns 12, the size of the string it contains
Print SizeOf(str1) 'returns 13, the size of the variableDim As ZString Ptr str2
str2 = Allocate( 13 )
*str2 = "hello, world"
Print *str2
Print Len(*str2) 'returns 12, the size of the string it containsCategory: Standard Data Types
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.
- 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