News for hackers. Stuff that matters.
Re:How to implement strings by bergesenha on Saturday November 03, 2018 @05:31PM (#18372583)
And in C++, the type of a string literal expression is not const char* , but in fact const char (&)[], ie a reference to an array of chars. I was surprised to learn this as I always assigned a literal to a const char* , relying on pointer decay without knowing it.
Re:How to implement strings by _kst_ on Saturday November 03, 2018 @06:51PM (#18372941)
In C, the type of a string literal is

    char[n]
where n is the length of the literal plus 1.

In C++, it's "array of n const char", or

    const char[n]
It's not of a reference type. See the ISO C++11 standard, 2.4.15 [lex.string].

(In both C and C++, array expressions "decay" to pointer expressions in most contexts. But for example

    sizeof "hello"
is 6 (the size of the string), not the size of a char* pointer.