News for hackers. Stuff that matters.
Re:Fixing C Strings by kelnos on Sunday December 22, 2024 @04:58PM (#42489499)
That's incorrect. If I write this in my .c file:

    char *s = "Hi";
The compiler will not treat that as a simple mere pointer to char when allocating space for it in the binary. It will see that the rhs is surrounded by double quote characters, and allocate 3 bytes for it, instead of 2, and put a NUL byte after the bytes for 'H' and 'i'.

Nul-tetminated strings are absolutely a part of the language. Certainly you can make and store strings in a different way if you'd like, but the language itself defines what a string and string literal is.

Re:Fixing C Strings by Quis_sum on Sunday December 22, 2024 @09:38PM (#42491222)
s is still a pointer to character. This is just an optimised shorthand for (assuming ASCII):

char s[3];

Which is then initialised with: 0x48,0x69,0x00

There simply is no such thing as a string type in C.

All the "string" functions work on a char pointer which is incremented until it points to a 0.