Types¶
As per the Basic types (official V documentation).
Stores value¶
Numeric¶
int
- 32-bit integerWarning
Current implementation falls back to pure C
int
type which is not always 32-bit. See #2480 for more.f32
- 32-bit floating-point number (seef32
implementation)byte
- 8-bit unsigned number, the smallest piece of memory which can contain basic character set such asASCII
Character set (seebyte
implementation)bool
- numeric type usingfalse
as negative value andtrue
as positive (currently inherited from C implementation)voidptr
- type holding a numeric value of a location in computer memory regardless its type or other properties, where user is responsible for the correct casting (converting) to certain types or manipulation with the value stored within the memory starting on that address - offsetting the stored memory address up to specified data container size (or its multiples).Considering x86 CPU and
int
type having 32-bit size, the starting value could be something like0x0000
and the data container being anint
would offset at0x0004
or in other words 4 bytes.Note
Void pointer does not have the knowledge of the offset required for program to retrieve a value from ones and zeroes starting at the numeric value stored in the void pointer itself i.e. void pointer does not store the value’s type.
References value¶
array
- structure holding pointers for a value or another pointer (seearray
for documentation andarray
implementation for implementation details)
Option
type¶
As per the Option types & error handling (official V documentation).
This kind of type is created by a ?
(question mark) prefix before an
ordinary type such as string
or an int
resulting in a ?string
return type for a function. This allows you to either return a correct value
for this type or mark the result of a function as a failure by using
return none
which forces the function caller to handle such a case with
either a compile error unhandled option type: `?type`
when you try to
access the value or a compile error saying this type does not have a method
for performing a certain action.
For example:
import os
content := os.read_file(<path>)
println(content)
does not compile due to `?string` needs to have method `str() string` to be
printable
, however a conversion to string
i.e. accessing the value
of ?string
type falls back to the original unhandled option type
error.
import os
content := os.read_file(<path>)
println(content.str())