On 15/04/2024 10:36 AM, Liam McGillivray wrote:
Well, it did work when I tried it (using a string variable, not a literal of course). It displayed as it is supposed to. But from the information I can find on the web it looks like strings are sometimes but not |always| zero-terminated. Not a great look for the language. Are there any rules to determine when it is and when it isn't (for string variables)?

String literals, which are constants that the compiler puts into ROM of the object file, are zero terminated because it doesn't cost anything to do this.

At runtime, unless you explicitly append the null terminator, no string contains it.

D's strings are slices, pointer + length. These are superior in both performance (not having to strlen all the time) and are safer (bounds checked access).

Null terminated strings are a technical debt due to legacy constraints. We would all be better off if C supported slices. Plenty of notable exploits couldn't of happened if they were used instead.
    • Re: "E... Liam McGillivray via Digitalmars-d-learn
      • Re: &qu... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... Liam McGillivray via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
            • ... Liam McGillivray via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
              • ... Steven Schveighoffer via Digitalmars-d-learn
              • ... Liam McGillivray via Digitalmars-d-learn
              • ... Steven Schveighoffer via Digitalmars-d-learn
              • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: "E... Liam McGillivray via Digitalmars-d-learn
      • Re: &qu... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... Liam McGillivray via Digitalmars-d-learn
          • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... Steven Schveighoffer via Digitalmars-d-learn
  • Re: "Error:... Kagamin via Digitalmars-d-learn

Reply via email to