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

  • Thread starter Steffen Fiksdal
  • Start date
S

Steffen Fiksdal

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
 
J

Jack Klein

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top