by _kst_ · 8y ago · 0 comments
"The C programming language defines a string as char* ."
No, it doesn't. A string is by definition "a contiguous sequence of characters terminated by and including the first null character". A char* value may or may not be a pointer to a string.
(Confusing arrays and pointers is perhaps the most common mistake people make when talking about C.)
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.Common Lisp has a list class that you can specialize a CLOS method on.
Also:
[1]> (typep nil 'list)
T
[2]> (typep '(a) 'list)
T
[3]> (typep 3 'list)
NIL
And: [4]> (subtypep 'cons 'list)
T ;
T
[5]> (subtypep 'null 'list)
T ;
T
So, kind of apples and oranges.char[n] (for constant n) is an array type. An object of type char[n] may or may not contain a string.