The following numeric data types are supported on 32-bit systems:
Code: Select all
bool - boolean (false (0) or true (-1)
int8 - 8 bits signed integer
uint8 - 8 bits unsigned integer
int16 - 16 bits signed integer
uint16 - 16 bits unsigned integer
int32 - 32 bits signed integer
uint32 - 32 bits unsigned integer
int - signed integer, architecture default size
uint - unsigned integer, architecture default size
real32 - 32 bits (4 bytes) floating point
real64 - 64 bits (8 bytes) floating point
real80 - 80 bits (10 bytes) extended floating point
ptr - pointer, architecture default size
Code: Select all
dim a: int;
dim b, c, d: uint;
dim x, y, z: real32 = 0;
dim p: ptr;
Code: Select all
str - null-terminated string
str * n - fixed length string, not null-terminated
chr8 - 8 bits (ascii) character
chr16 - 16 bits (2 bytes) character
chr32 - 32 bits (4 bytes) character
Code: Select all
const msg = "these are character data types";
dim text: str;
dim f: str * 255;
dim c: chr8;
The character family, chr8, chr16 and chr32, is particularly useful with arrays for specific text encodings, such as UTF8, UTF16 and UTF32, or any other encoding that fits the appropriate character type. Note that a chr8 array declaration would be the same as a byte-string of type str.
SharpBASIC also supports a general buffer type, which can be declared as either byte (8 bits), word (16 bits) or dword (32 bits). Buffer types are declared with the dim statement and the length of the buffer must be specified similar to the fixed-length string. The difference between a buffer type and a fixed-length string is that a buffer type does not have a descriptor. Basically, a buffer type is the same as a const string type, except the data of a buffer type can be changed. Neither are null-terminated.
Example of buffer type declarations:
Code: Select all
dim bdata: byte * 256; ' 256 bytes buffer
dim wdata: word * 256; ' 512 bytes buffer (256 * 2)
dim ddata: dword * 256; ' 1024 bytes buffer (256 * 4)
buffer type example:
Code: Select all
dim bdata : byte * 26; ' 26 bytes buffer
dim s : str * 26; ' 26 bytes fixed length string
dim size : uint8;
dim i: uiter;
dim pb, ps : ptr;
main do
' buffer size
size = len(bdata);
' buffer address
pb = aof(bdata);
' populate buffer
for i = 0 to size - 1 :++
do
stob(pb + i, 65 + i);
end
' fixed length string address
ps = sadd(s);
' copy buffer to string
cpmem(pb, ps, size);
' print string
print(s);
end
Code: Select all
01 - bool
02 - int8
03 - uint8
04 - int16
05 - uint16
06 - int32
07 - int
08 - uint32
09 - uint
10 - real32
11 - real64
12 - real80
13 - [reserved]
14 - ptr
15 - str
16 - chr8
17 - chr16
18 - chr32
19 - [reserved]
20 - byte
21 - word
22 - dword
23 - udt (user-defined type)
Code: Select all
dim s: str = "Hello world!";
main do
if typof(s) == 15 do
print(s);
end
end