Hacker Times
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
saagarjha
on June 26, 2018
|
parent
|
context
|
favorite
| on:
Massacring C Pointers
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
on June 26, 2018
[–]
Well to be pedantic C++'s type system doesn't check for that either it just passes around a size_t and char *.
saagarjha
on June 26, 2018
|
parent
[–]
I was referring to std::string, which is what you should be using if you're handling textual data natively.
nwmcsween
on June 27, 2018
|
root
|
parent
|
next
[–]
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
on June 26, 2018
|
root
|
parent
|
prev
[–]
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.
saagarjha
on June 26, 2018
|
root
|
parent
[–]
I'd suggest using a std::vector of byte-sized integers for clarity, though there's nothing wrong from a standards point in using a std::string.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: