Repository navigation
Category Nullptr
Home › All Categories › Nullptr
nullptr is the null pointer. tiko predeclares it as
const nullptr as any ptr = 0so it is an any ptr whose value is 0. It assigns to, and compares with, every pointer type — typed, zstring ptr, procedure pointers, UDT pointers — with no warning, and if p then treats it as false.
type Node
nxt as Node ptr
end type
dim as Node ptr head = nullptr
dim as zstring ptr name_ = nullptr
dim as sub( ) callback = nullptr
if head = nullptr then print "empty list"0 is an integer. Where the target is already a pointer that makes no difference, but where the compiler has to choose a type it chooses integer:
| Code | With 0
|
With nullptr
|
|---|---|---|
F( x ), overloads F( integer ) and F( any ptr )
|
calls F( integer )
|
calls F( any ptr )
|
var p = x |
p is an integer
|
p is an any ptr
|
Echo( x ), function Echo( of T )( byval v as T ) as T
|
T is integer
|
T is any ptr
|
C++11 and C23 added nullptr for the same reason.
nullptr converts to every pointer type equally, so a call that could take it as either of two pointer types is ambiguous, as it is in C++:
sub G overload ( byval a as long ptr )
end sub
sub G overload ( byval a as zstring ptr )
end sub
G( nullptr ) '' TKO0660, with a note naming the fix
G( cptr( zstring ptr, nullptr ) ) '' the fixnullptr is a constant, not a reserved word, for the same reason the fixed-width type names are typedefs: programs may use the name for their own declarations. Whatever a program declares called nullptr — a field, a namespace member, a local, a parameter, a for counter, a module-level variable — replaces tiko's there, with no diagnostic.
0 keeps its meanings alongside it: p = 0 and if p = 0 are legal and silent.
Storing nullptr — or any pointer — into a pointer-sized integer is warning TKO0968:
dim as integer n = nullptr '' TKO0968: implicit conversion
dim as integer m = cast( integer, nullptr ) '' silenttiko-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