Re: [dev] alternatives to C: Ada, Rust, Pascal

From: Vincent Lefevre <vincent_AT_vinc17.net>
Date: Sat, 22 Jun 2024 10:45:32 +0200

On 2024-06-22 03:58:46 +0000, NRK wrote:
> Sized strings
> -------------
>
> typedef struct {
> uint8_t *s; // or you can use `(unsigned) char *`
> ptrdiff_t len; // or you can use `size_t`, see explanation below
> } Str;
>
> * Cheap access to the string length which allows expressing string
> operations much more naturally (read: less error prone).
> * Zero copy sub-string. This is a huge one, because it avoids many
> spurious copies and/or allocations.

This is OK if your string is constant. Otherwise, this may be
dangerous, e.g. in case the full string is changed in place.

-- 
Vincent Lefèvre <vincent_AT_vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Received on Sat Jun 22 2024 - 10:45:32 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 22 2024 - 10:48:09 CEST