Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
leodeid
· 8y ago · 0 comments
Sure, but it is still a valid 'char *' :)
Comments
[–]
saagarjha
8y ago
That's something C's type system doesn't check for. If you want protection for this case, use C++ or any other higher-level language instead.
[–]
nwmcsween
8y ago
Well to be pedantic C++'s type system doesn't check for that either it just passes around a size_t and char *.
[–]
saagarjha
8y ago
I was referring to std::string, which is what you should be using if you're handling textual data natively.
[–]
nwmcsween
8y ago
The implementation of std::string is 99.999% of the time struct { char *s; size_t len; }, which has nothing to do with an actual type.
[–]
gmueckl
8y ago
And it's even possible to use std::string as a buffer for binary data including NULs. I won't recommend it, but it works.