Stage 110-112: buffer type revisited

Follow the development of the SharpBASIC compiler and share your thoughts and ideas.
Locked
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Stage 110-112: buffer type revisited

Post by frank »

A buffer type was introduced last year, but it was limited to access by pointer. Some features have been added to make it easier and more flexible to work with buffers as placeholders for data:

- the function cbuf copies data types to a buffer.

Code: Select all

buffer = cbuf(string)
whereby an optional parameter can set a specific offset into the buffer:

Code: Select all

buffer = cbuf(string, 20)
- the routine clbuf clears a buffer:

Code: Select all

clbuf(buffer)
whereby an optional parameter can set a specific character to fill the buffer (the default is space, ascii character 32)

Code: Select all

clbuf(buffer, 45)
Manipulating buffers are important as the buffer type can be used as a record element:

Code: Select all

record device is
  block_id: uint8;
  block_name: byte * 8;    ' buffer
  block_size: uint;
end
Examples of buffer datatypes are in the wiki.

The record as a user-defined type is currently being implemented. While in the process, the UDT struc is also being revisited. The major difference between records and structures in SharpBASIC is that records have a fixed length and cannot hold strings (not even fixed-length strings).
Last edited by frank on Thu Jul 27, 2023 7:06 am, edited 3 times in total.
Keep it simple!
Locked