Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > char, unsigned char, and binary file io

Reply
Thread Tools

char, unsigned char, and binary file io

 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      04-22-2004
glen_stark wrote:
>
> Hi.
>
> I have code for reading and writing gds files that I have inherited from
> a company and need to make standards compliant. Unfortunately the code
> is heavily dependant on the win api. I think I can get around
> everything but one stumbling point I would like some advice on.
>
> The win api uses an unsigned char array for writing binary data to and
> from the gds file. Now, one reason I want standards compliant code is
> to be able to run my code on a variety of different machines, so I can't
> count on the same representation of char (as signed or unsigned).
>
> The std iostream however, uses plain char for binary output (please let
> me know if I am missing anything). I need to be able to read and write
> these files from any machine, and be able to read the files written by
> users of the company code.
>
> So what I need to do is make sure that char array I am passing to
> std::write contains an unsigned char binary representation.


stick with unsigned char and cast the pointer you give
to read() and write() to char*. read() and write() will do
nothing to the chars if you open the file in binary mode.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
glen_stark
Guest
Posts: n/a
 
      04-22-2004
Hi.

I have code for reading and writing gds files that I have inherited from
a company and need to make standards compliant. Unfortunately the code
is heavily dependant on the win api. I think I can get around
everything but one stumbling point I would like some advice on.

The win api uses an unsigned char array for writing binary data to and
from the gds file. Now, one reason I want standards compliant code is
to be able to run my code on a variety of different machines, so I can't
count on the same representation of char (as signed or unsigned).

The std iostream however, uses plain char for binary output (please let
me know if I am missing anything). I need to be able to read and write
these files from any machine, and be able to read the files written by
users of the company code.

So what I need to do is make sure that char array I am passing to
std::write contains an unsigned char binary representation.

How can I take a char, and cast it to a double (or int, or whatever),
interpreting, taking care to interpret it as an unsigned char? And vice
versae?

Thanks for your time.
 
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
Printing the range s of unsigned char and unsigned int. Junmin H. C Programming 20 09-20-2007 06:03 AM
comparing unsigned long and unsigned int sridhar C Programming 6 11-03-2004 03:52 AM
unsigned int const does not match const unsigned int Timo Freiberger C++ 3 10-30-2004 07:02 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments