Why null-terminated strings? Or: null-terminated vs. characters + length storage

后端 未结 10 1284
-上瘾入骨i
-上瘾入骨i 2020-12-23 17:29

I\'m writing a language interpreter in C, and my string type contains a length attribute, like so:

struct String
{
    char* charac         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 17:49

    Just throwing out some hypotheticals:

    • there's no way to get a "wrong" implementation of null terminated strings. A standardized struct however could have vendor-specific implementations.
    • no structs are required. Null terminated strings are "built-in" so to speak, by virtue of being a special case of a char*.

提交回复
热议问题