Re:Checked C: extension to C that adds static and dynamic ch...
by rs86 on Wednesday March 14, 2018 @08:52PM
(#16589679)
Arrays are actually pointers to the first element... They get translated to pointer arithmetic: adding an offset to the first element. You can easily create a struct with one field for the size and another with the pointer to the first character
[ Parent
| on HN ]
Re:Checked C: extension to C that adds static and dynamic ch...
by kqr on Thursday March 15, 2018 @01:44AM
(#16590652)
Semantically, arrays are different from pointers. They do, however, degrade into pointers in many situations, which causes that misunderstanding.
Re:Checked C: extension to C that adds static and dynamic ch...
by petecox on Thursday March 15, 2018 @02:07AM
(#16590740)
A language with an array type, e.g. Java, distinguishes between a 'null' array reference and an array of zero length. which could substitute in languages that don't have an option type; SOME([]) vs NONE
But a plain *char in C makes no such distinction.
Re:Checked C: extension to C that adds static and dynamic ch...
by charliesome on Thursday March 15, 2018 @03:32AM
(#16591011)
There is a difference. An empty string in C is a non-null char* pointer pointing to a zero byte. Passing a null pointer to strlen will crash.
Re:Checked C: extension to C that adds static and dynamic ch...
by esrauch on Thursday March 15, 2018 @03:46AM
(#16591052)
A zero-length array can't ever be a valid cstring at all since they have to be null terminated. I don't think that is actually relevant to the claim you are replying to, which is about arrays and pointers and not strings.