C Null-Terminated Strings

Comments criticize C's null-terminated strings for performance issues, safety risks like buffer overflows, and inconsistent standard library functions, while discussing alternatives like length-prefixed strings and safer APIs such as strlcpy.

📉 Falling 0.3x Programming Languages
4,881
Comments
20
Years Active
5
Top Authors
#3305
Topic ID

Activity Over Time

2007
1
2008
4
2009
44
2010
114
2011
121
2012
147
2013
209
2014
310
2015
201
2016
239
2017
172
2018
422
2019
359
2020
298
2021
555
2022
464
2023
520
2024
363
2025
318
2026
28

Keywords

e.g NULL OsString HEAD AsciiStrToUpper NUL IMO HN UX E.g string strings terminated null functions length library standard library character standard

Sample Comments

GoblinSlayer Apr 24, 2023 View on HN

C already has bad performance due to null terminated strings.

cozzyd Mar 13, 2025 View on HN

String handling is certainly one of C's main weaknesses

_mlbt Sep 4, 2025 View on HN

C style null terminated strings were a mistake. They are almost never the right answer. Even C itself should start transitioning to length prefixed strings instead.

guitarbill Aug 7, 2019 View on HN

I think BSD has strlcpy and strlcat for exactly this reason

heinrich5991 Feb 19, 2015 View on HN

E.g. null-terminated strings without length perform badly in some operations.

auslander Jul 22, 2018 View on HN

Wiki on subj:https://en.wikipedia.org/wiki/C_string_handling#Replacements

thelopa Jun 2, 2023 View on HN

Many of the str functions in the C standard library assume a nul terminator.

SunlitCat Jun 3, 2025 View on HN

Strings! The bane of C programming, and a big reason I prefer C++. :D

jasonhansel Aug 25, 2019 View on HN

Nice. Is there a similar standalone C library for safe/sane string handling? (Please don't tell me to use C++.)

zokier Sep 12, 2019 View on HN

C-coders of HN, do you use plain vanilla C strings in your project (s)? I was under the impression that most (at least bigger ones) use some custom length carrying string type to avoid exactly these sort of problems