J
Jonathan Lee
OK stupid question time.
What's the proper way to process char data as unsigned char? A lot of
the things I write are only defined on "raw" data. Like, huffman
decoding, or block ciphers. But a lot of this data comes from files or
strings which are char sources. The way I've been handling this until
now is to simply reinterpret_cast<> a pointer to a char buffer into an
unsigned char pointer. Like
// convenience
void encrypt(const char* data, std::size_t n) {
encrypt(reinterpet_cast<const unsigned char*>(data, n);
}
// "real" function
void encrypt(const unsigned char* data, std::size_t n) {
..
}
I don't see any guarantee in the standard that this will work, and
it's bugging me.
So... really what should I be doing?
--Jonathan
What's the proper way to process char data as unsigned char? A lot of
the things I write are only defined on "raw" data. Like, huffman
decoding, or block ciphers. But a lot of this data comes from files or
strings which are char sources. The way I've been handling this until
now is to simply reinterpret_cast<> a pointer to a char buffer into an
unsigned char pointer. Like
// convenience
void encrypt(const char* data, std::size_t n) {
encrypt(reinterpet_cast<const unsigned char*>(data, n);
}
// "real" function
void encrypt(const unsigned char* data, std::size_t n) {
..
}
I don't see any guarantee in the standard that this will work, and
it's bugging me.
So... really what should I be doing?
--Jonathan