Having Trouble

P

pete

The said:
The standard guarantees: CHR_BITS >= 8

That is the world outside the C continuum interprets
char = 8 bits.

But hardware designers are sometimes crude and defines that
the mashine should have no possibility to address less than
9, 12, 16 or 32 or.... bits. As C is designed to be
effective it will then define char bits as the smallest number
of bits the mashine can address in its memory.

As external chars are commonly exactly 8 bit wide the
implementation will transfer the 8 bit to the internal
char wide and reverse. The result will be that your
32 bit char has 24 bits unused (or sign extended in case of
signed char.

So when your implementation tells you that sizeof(char) == sizeof(int)
== sizeof(long) == 1 then your
- unsigned char uses 8 bits,

If sizeof(long) equals one,
then unsigned char, uses at least 32 bits.
If sizeof(long) equals one,
then UCHAR_MAX is at least 0xffffffff.
the sign bit ignored

What sign bit ?
unsigned char doesn't have a sign bit.
and the unused bits zeroed (or set mashine dependant)

What?
Are you still talking about unsigned char ?
 
B

Ben Pfaff

Joona I Palaste said:
Then, how is the C implementation able to distinguish between EOF and a
real char? If char and int are signed, I can very well envision a
scenario where a byte of all-bits-one would be mistaken for EOF.

It's possible. Most C programmers choose to ignore the
possibility. If you want to distinguish, call feof().
 
D

Dave Thompson

In fact EOF is guaranteed NOT to fit into a char.

It is implementation-defined whether plain char is signed or unsigned.
If signed, the usual (though not required) value for EOF, -1, fits.

- David.Thompson1 at worldnet.att.net
 

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

No members online now.

Forum statistics

Threads
474,077
Messages
2,570,568
Members
47,204
Latest member
abhinav72673

Latest Threads

Top