Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > void*, char*, unsigned char*, signed char*

Reply
Thread Tools

void*, char*, unsigned char*, signed char*

 
 
Steffen Fiksdal
Guest
Posts: n/a
 
      05-08-2005

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




 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      05-09-2005
On Sun, 8 May 2005 22:41:25 +0200, Steffen Fiksdal
<> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
Convert a signed binary number into a signed one ? Rob1bureau VHDL 1 02-27-2010 12:13 AM
signed(12 downto 0) to signed (8 downto 0) kyrpa83 VHDL 1 10-17-2007 06:58 PM
signed to unsigned Patrick VHDL 1 06-07-2004 01:59 PM
STD_LOGIC_VECTOR vs. UNSIGNED vs. SIGNED Jeremy Pyle VHDL 3 06-28-2003 10:47 PM



Advertisments