"Error: `TypeInfo` cannot be used with -betterC" on a CTFE function
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sun Apr 14 23:12:05 UTC 2024
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.
More information about the Digitalmars-d-learn
mailing list