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

后端 未结 10 1298
-上瘾入骨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:54

    I think main reason is that standard says nothing concrete about size of any type other than char. But sizeof(char) = 1 and that is definitely not enough for string size.

提交回复
热议问题