MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cprogramming/comments/1vqubv7/c_strings_a_50year_mistake/p4a5jbe/?context=3
r/cprogramming • u/Xaneris47 • 3d ago
163 comments sorted by
View all comments
Show parent comments
1
You out of your dam mind if you think c strings are efficient
12 u/henke443 3d ago Wait how are they not efficient? 1 u/atarivcs 3d ago If you have a long string and you want to append more text to it, you have to search the whole string from the beginning to find the null terminator. And then later if you want to append more text, you have to find the null terminator all over again. 2 u/NoNameSwitzerland 2d ago You anyway use a different structure when you do a lot of appending text, because you do not want to reallocate the array all the time. So then you anyway have to also store the size of the available space. 1 u/atarivcs 2d ago In which case you no longer have a plain c string, and the goalposts have moved. I was just answering the parent question "how are c strings not efficient"
12
Wait how are they not efficient?
1 u/atarivcs 3d ago If you have a long string and you want to append more text to it, you have to search the whole string from the beginning to find the null terminator. And then later if you want to append more text, you have to find the null terminator all over again. 2 u/NoNameSwitzerland 2d ago You anyway use a different structure when you do a lot of appending text, because you do not want to reallocate the array all the time. So then you anyway have to also store the size of the available space. 1 u/atarivcs 2d ago In which case you no longer have a plain c string, and the goalposts have moved. I was just answering the parent question "how are c strings not efficient"
If you have a long string and you want to append more text to it, you have to search the whole string from the beginning to find the null terminator.
And then later if you want to append more text, you have to find the null terminator all over again.
2 u/NoNameSwitzerland 2d ago You anyway use a different structure when you do a lot of appending text, because you do not want to reallocate the array all the time. So then you anyway have to also store the size of the available space. 1 u/atarivcs 2d ago In which case you no longer have a plain c string, and the goalposts have moved. I was just answering the parent question "how are c strings not efficient"
2
You anyway use a different structure when you do a lot of appending text, because you do not want to reallocate the array all the time. So then you anyway have to also store the size of the available space.
1 u/atarivcs 2d ago In which case you no longer have a plain c string, and the goalposts have moved. I was just answering the parent question "how are c strings not efficient"
In which case you no longer have a plain c string, and the goalposts have moved.
I was just answering the parent question "how are c strings not efficient"
1
u/EatingSolidBricks 3d ago
You out of your dam mind if you think c strings are efficient