On Sun, 8 May 2005 22:41:25 +0200, Steffen Fiksdal
<st******@ulrik.uio.no> wrote in comp.lang.c:
I have a function that base64 decodes some data. The incoming data is
received as "const char*" (BASE64 characters are always safe ASCII
characters, meaning they will always fit in a signed char positive range).
The resulting decoded data is placed in memory, and the function exposes
an "unsigned char*" to the caller.
What does ANSI C say (if anything) about what kind of pointer is the
correct one to use for passing/returning/processing binary data locations ?
Best regards
Steffen
Binary data is best read as unsigned characters, and this is a
particularly good idea to use them for base64 encoding/decoding as you
need to do bit shifting. Bit shifting can be questionable using
signed types.
Use a pointer to unsigned char to access the data as unsigned
characters, and use unsigned longs to accumulate and shift them.
There is no need to cast away the const if you are only reading the
bytes.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html