On Monday, 27 June 2016 at 05:27:12 UTC, chmike wrote:
Ending strings with a single null byte/char is to save space. It was critical in the 70´s when C was created and memory space was very limited. That's not the case anymore and I guess the

Not only to save space, some CPUs also had cheap incrementing load/stores and branching on zero is faster than sacrificing another register for a counter.

IIRC Pascal has a short string with a single byte length.

Besides there are plenty of other advantages to using a terminating sentinel depending on the use scenario. E.g. if you want many versions of the same tail or if you are splitting a string at white space (overwrite a white space char with a zero).
  • 4x faster strlen with 4 ch... Jay Norwood via Digitalmars-d-announce
    • Re: 4x faster strlen ... David Nadlinger via Digitalmars-d-announce
      • Re: 4x faster str... Jay Norwood via Digitalmars-d-announce
        • Re: 4x faster... chmike via Digitalmars-d-announce
          • Re: 4x fa... chmike via Digitalmars-d-announce
            • Re: ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Jay Norwood via Digitalmars-d-announce
                • ... Ola Fosheim Grøstad via Digitalmars-d-announce
                • ... Jay Norwood via Digitalmars-d-announce
                • ... Ola Fosheim Grøstad via Digitalmars-d-announce
                • ... Jay Norwood via Digitalmars-d-announce
                • ... Ola Fosheim Grøstad via Digitalmars-d-announce
                • ... Mike Parker via Digitalmars-d-announce
              • ... Ola Fosheim Grøstad via Digitalmars-d-announce
        • Re: 4x faster... Brad Roberts via Digitalmars-d-announce
    • Re: 4x faster strlen ... deadalnix via Digitalmars-d-announce

Reply via email to