Sebbe's Lemmy
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
LalSalaamComrade@lemmy.ml to General Programming Discussion@lemmy.mlEnglish · 1 year ago

Are there better alternatives to null-terminated strings?

message-square
message-square
11
link
fedilink
1
message-square

Are there better alternatives to null-terminated strings?

LalSalaamComrade@lemmy.ml to General Programming Discussion@lemmy.mlEnglish · 1 year ago
message-square
11
link
fedilink
  • SubArcticTundra@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    Another alternative I’ve seen is strings that are not null terminated but where the allocated memory actually begins at ptr[-1] and contains the length of the string. The benefit is that you still get a char array starting at ptr[0].

    • LalSalaamComrade@lemmy.mlOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      But wouldn’t this be potentially unsafe? What programming language has this type of implementation, by the way?

      • SubArcticTundra@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        1 year ago

        Hmm I think I saw it in a C library

        Edit: Might have been this one https://github.com/msteinert/bstring

        Edit: actually seems it’s this one. Look at what happens to ystr_header_t https://github.com/Amaury/Ylib/blob/master/src/ystr.c

General Programming Discussion@lemmy.ml

programming@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

A general programming discussion community.

Rules:

  1. Be civil.
  2. Please start discussions that spark conversation

Other communities

  • [email protected]
  • [email protected]
  • [email protected]
  • [email protected]

Systems

  • [email protected]
  • [email protected]
  • [email protected]

Functional Programming

  • [email protected]
  • [email protected]

Also related

  • [email protected]
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1 user / day
  • 1 user / week
  • 6 users / month
  • 83 users / 6 months
  • 0 local subscribers
  • 9K subscribers
  • 309 Posts
  • 313 Comments
  • Modlog
  • mods:
  • Evan@lemmy.ml
  • Restioson@lemmy.ml
  • BE: 0.19.11
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org