Meaning of unsigned char

F

Frederick Gotham

Keith Thompson posted:
Fascist? Sheesh, get a grip! (And my name is Keith, not Kieth.)

It's possible that you've confused the word "perverse" with
"perverted". If so, your gross overreaction is almost understandable.


No confusion.

Here's the definition of "perverse" from the Merriam Webster Dictionary:

1 a : turned away from what is right or good : corrupt b :
improper, incorrect c : contrary to the evidence or the direction
of the judge on a point of law <perverse verdict>
2 a : obstinate in opposing what is right, reasonable, or accepted
: wrongheaded b : arising from or indicative of stubbornness or
obstinacy
3 : marked by peevishness or petulance : cranky
synonyms: see contrary

Not all of these apply, but in my opinion several of them do. Writing
"char unsigned" is not incorrect; it is merely perverse.


This is exactly what I'm talking about -- you label my way of doing things
as "perverse", even though it is perfectly OK. The word "perverse" has
negative connotations. If you're looking for a more neutral word along the
same lines, then perhaps try "uncommon".

Furthermore, you conciously introduced me to a newbie in a disrespectful
way -- stating that my methods are "perverse".

And here's the definition of "fascism" from the same dictionary:

1 often capitalized : a political philosophy, movement, or regime
(as that of the Fascisti) that exalts nation and often race above
the individual and that stands for a centralized autocratic
government headed by a dictatorial leader, severe economic and
social regimentation, and forcible suppression of opposition
2 : a tendency toward or actual exercise of strong autocratic or
dictatorial control <early instances of army fascism and brutality
J. W. Aldridge>

How this applies to what I did (expressing my opinion in a public
forum) I can't imagine.


You are forcing you're way of doing things down other people's throats, and
labelling any other way of doing things as "perverse". That's what I see as
fascist.
 
C

Chris Hills

Frederick Gotham said:
Keith Thompson posted:


A note to the original poster: The C language has a less-than-strict syntax
when it comes to word ordering. A lot of the time, the programmer has
choice over what order to put the words in; for instance, all of the
following definitions are equivalent:

const unsigned long int i = 5;
int long unsigned i const = 5;
cont int long unsigned i = 5;
int unsigned const long i = 5;

You will find that many C programmers (Keith Thompson included)

I would say virtually "ALL" programmers would agree with Keith... Even
me! (Sorry Keith :)
I suggest to the original poster that he or she write their definitions in
whatever word order they like best.


I would not. I would suggest you stick to [un]signed char. Doing it the
other way round will not help you in any way but will confuse many.
 
A

Ancient_Hacker

The real reason there's even a distinction is based on the original
hardware that C was designed to run on. That was the PDP-11 CPU. The
'11 had very many superb features in its instruction set, but a few
quirks also. IIRC the byte comparison instruction did only a signed
compare, and using a byte register as an index would do a signed
address calculation. Also using a byte register in a word context
would sign extend the byte to 16 bits. Not to mention pointers and
registers were 16-bits wide only, so it was CRITICAL to do unsigned
arithmetic with pointers.

So the C designers were very much aware of the differences between
signed byte (-128 to 127) arithmetic versus unsigned byte (0 to 255)
arithmetic versus signed and unsigned 16-bit arithmetic.

You'll see vestiges of this on other architectures that have signed
bytes, like the POWER PC. A common error is using a "char" to get the
result of getopt(), which results in an infinite loop when getopt tries
to return the end of options code.
 
I

Ivanna Pee

sarathy said:
Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET

2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET

What does it mean for a character to be signed ? Is there any
difference between signed and unsigned char ? If Yes, how do they

For a signed char the most significant bit is treated as a SIGN
bit(positive or negative) and the remainder is the magnitude ~ (2^7).
For an unsigned char there is no sign bit, and the magnitude is (2^8)
-1.

The same can be applied to the other data types, with appropriate
magnitudes.
 
C

Chris Dollin

Ancient_Hacker said:
The real reason there's even a distinction is based on the original
hardware that C was designed to run on. That was the PDP-11 CPU. The
'11 had very many superb features in its instruction set, but a few
quirks also. IIRC the byte comparison instruction did only a signed
compare, and using a byte register as an index would do a signed
address calculation. Also using a byte register in a word context
would sign extend the byte to 16 bits.

The PDP-11 didn't have "byte registers".

You may be thinking of the behaviour of the MOVB instruction, which
IIRC did sign-extension when the target was a register.
Not to mention pointers and
registers were 16-bits wide only, so it was CRITICAL to do unsigned
arithmetic with pointers.

Again, IIRC, the PDP-11 didn't have "unsigned arithmetic". It just
had twos-complement arithmetic. The condition codes were set as
a result of the add/subtract instructions and it was up to the
following code as to how it dealt with the V or C bits being set.

Just because some addresses would be negative if you treated them
as numbers doesn't mean you had to so something special, not that
I can see anyway.
 
A

Al Balmer

The real reason there's even a distinction is based on the original
hardware that C was designed to run on.

Please quote context. This doesn't even have any relation to the
message you're replying to!
 
A

Al Balmer

Keith Thompson posted:



No. I would point out though that your use of "perverse" was unsuitable.
Since the subject has been beaten past the point of topicality anyway,
what's your objection to "perverse"? Dictionary.com gives four
meanings:

1. Directed away from what is right or good; perverted.
2. Obstinately persisting in an error or fault; wrongly self-willed
or stubborn.
3.
a. Marked by a disposition to oppose and contradict.
b. Arising from such a disposition.
4. Cranky; peevish.

And it seems to me that all four apply here ;-)
 
A

Al Balmer

Secondly, respect is fleeting on Usenet. I'm usually accepted quite
graciously at the beginning on newsgroups such as this one, but then when I
don't immediately submit to fascism such as "Don't write it that way, it
confuses us", or "Use signed integer types, not unsigned", the transparency
of any perceived respect becomes apparent.

Did it ever occur to you that there just might be another reason for
the perceived change in others' respect for you? Think about it. It
might be a clue.
 
W

Walter Roberson

Ivanna Pee said:
For a signed char the most significant bit is treated as a SIGN
bit(positive or negative) and the remainder is the magnitude ~ (2^7).
For an unsigned char there is no sign bit, and the magnitude is (2^8)
-1.
The same can be applied to the other data types, with appropriate
magnitudes.

Well, that is one of the possibilities in C, but it is not
very common.

C99 places some representation restrictions that did not explicitly
exist in C89. C99 allows three different representations for
signed integers: two's complement, one's complement, and seperate sign
("signed magnitude").

What you have described is signed magnitude. In what you have
described, binary 11111111 is "sign bit set, magnitude binary 1111111"
which would be -127 (decimal). In the much more common two's complement,
the same bit pattern would represent -1 (decimal).
 
S

Simon Biber

Frederick said:
Labeling it as "perverse" because it clashes with other people's styles
borders on fascist ideals not unlike one expressing and asserting one's
homphobia.

I don't think that it's quite that serious.
Kieth Thompson likes to write "unsigned char"... great! Would you not
consider it fascist that he labels any other perfectly conforming way of
doing it as "perverse"?

C keywords are written in the English language. "unsigned" is an
adjective, while "character" and "integer" (from which "char" and "int"
are derived) are nouns. In English the usual word order requires
adjectives to come before the noun that they modify. To an English
speaker, "char unsigned" makes no sense while "unsigned char" makes much
more sense. A French speaker may feel the opposite is true.
Not when people are trying to persuade me that there's an inherent flaw in
writing "char unsigned". Both from reading the Standard, and from my own
programming experience, I have not been convinced that "char unsigned" is
bad style.

An English speaker generally finds it easier to read code that reads
like English.

If the C keywords had been "with sign" and "without sign" then we would
find it natural to write "char without sign" and not "without sign char".
 
C

Clark S. Cox III

I was deliberately not denying the possibility (however remote) that
there might be another.

While I can't say that I've ever written 'char unsigned' in my C code,
I have written 'char const' in some of my C++ code, as this is the
convention used by the boost libraries when passing pointer <OT>or
reference</OT> parameters.

Though, I have never seen a compelling reason as to why one would put
the 'unsigned' after the 'char/short/int/long/long long', it can make
sense to put the 'const' (or 'volatile') after the type that it
modifies, as it normalizes the order somewhat (i.e. const modifies the
thing that immediately precedes it)

For example:

(char const) - a constant char
(char const *) - a pointer to a constant char (i.e. 'const' modifies 'char')
(char * const ) - a constant pointer to a char (i.e. 'const' modifies '*')
(char const * const ) - a constant pointer to a constant char
 
C

Clark S. Cox III

Robert Gamble posted:



Labeling it as "perverse" because it clashes with other people's styles
borders on fascist ideals not unlike one expressing and asserting one's
homphobia.

Do you even know what the word "perverse" means?

From my dictionary:

perverse |pÉ™rˈvÉ™rs| |pÉ™rËŒvÉ™rs| |pəˌvÉ™Ës|
adjective
(of a person or their actions) showing a deliberate and obstinate
desire to behave in a way that is unreasonable or unacceptable, often
in spite of the consequences : Kate's perverse decision not to
cooperate.

That describes your apparent attitude pretty accurately.
Kieth Thompson likes to write "unsigned char"... great! Would you not
consider it fascist that he labels any other perfectly conforming way
of doing it as "perverse"?




Not when people are trying to persuade me that there's an inherent flaw
in writing "char unsigned". Both from reading the Standard, and from my
own programming experience, I have not been convinced that "char
unsigned" is bad style.

The inherent flaw is that it's different for no reason other than being
different. If it were different because it was objectively better, then
nobody would have a problem with it.
 
A

Ancient_Hacker

Chris said:
The PDP-11 didn't have "byte registers".

You may be thinking of the behaviour of the MOVB instruction, which
IIRC did sign-extension when the target was a register.

IIRC ALL the two-operand instructions had a bit that controlled whether
the instruction worked on words or bytes. So you had not only MOVB,
but ADDB, SUBB, XORB, CLRB, BISB, BICB, ROLB, etc.... all of which
operated on bytes, in memory or in the lower byte of a register. I
guess the reason I misspoke about "byte registers" is that the handy
little pocket-guide to PDP-11 instructions has the registers
partitioned in half. And they certainly behave as 8-bit registers if
you set that bit.

You're also correct in that there was no separate "unsigned arithmetic"
mode per se, you just had to interpret the sign and overflow states
differently when using unsigned numbers. This became a really big
deal once folks could afford more than 32K of memory-- I remember a lot
of address comparisons broke once addresses could go "negative".
 
C

Clark S. Cox III

Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET

2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET

What does it mean for a character to be signed ? Is there any
difference between signed and unsigned char ? If Yes, how do they

For a signed char the most significant bit is treated as a SIGN
bit(positive or negative) and the remainder is the magnitude ~ (2^7).
For an unsigned char there is no sign bit, and the magnitude is (2^8)
-1.

Note that the signed types don't necessarily have sign and magnitude
representations (and, on current systems, usually don't). It is far
more common to find two's compliment representations.
 
I

Ivanna Pee

Walter said:
Well, that is one of the possibilities in C, but it is not
very common.

C99 places some representation restrictions that did not explicitly
exist in C89. C99 allows three different representations for
signed integers: two's complement, one's complement, and seperate sign
("signed magnitude").

What you have described is signed magnitude. In what you have
described, binary 11111111 is "sign bit set, magnitude binary 1111111"
which would be -127 (decimal). In the much more common two's complement,
the same bit pattern would represent -1 (decimal).

I concur. I was just surprised that in all the responses noone
mentioned a sign bit to the OP. I didn't want to further confuse the OP
with compliment arithmetic, I simply used the word 'magnitude' without
specifics.
 
W

Walter Roberson

Walter said:
I concur. I was just surprised that in all the responses noone
mentioned a sign bit to the OP. I didn't want to further confuse the OP
with compliment arithmetic, I simply used the word 'magnitude' without
specifics.

The problem is that your description is not correct for two's
complement representation, because it implies that there is a sign
bit that does not take part in the value representation. In
two's complement representation, the sign bit does officially take part
in the value representation. For example if signed char happened to
be 8 bits, then in two's complement, 0x80 is not "sign bit set, magnitude
bits all 0" (such as might be used to store negative 0 or negative 1):
it would be either a trap representation or else it would be
(0x80 - 0xFF - 1) (that is, 128 - 255 - 1). In this formulation, the value
of all of the bits take part in the calculation. (Whether they officially
officially all take part in the calculation or not only matters for the
case where what you have called the magnitude bits are all 0.)
 
K

Keith Thompson

Frederick Gotham said:
Keith Thompson posted:

No confusion.

Ok, so your gross overreaction is not understandable.
Here's the definition of "perverse" from the Merriam Webster Dictionary: [snip]
Not all of these apply, but in my opinion several of them do. Writing
"char unsigned" is not incorrect; it is merely perverse.

This is exactly what I'm talking about -- you label my way of doing things
as "perverse", even though it is perfectly OK. The word "perverse" has
negative connotations. If you're looking for a more neutral word along the
same lines, then perhaps try "uncommon".

Let me be very clear. If I had wanted to use a more neutral word, I
would have used one.
Furthermore, you conciously introduced me to a newbie in a disrespectful
way -- stating that my methods are "perverse".

Yes, I did.
And here's the definition of "fascism" from the same dictionary: [snip]
How this applies to what I did (expressing my opinion in a public
forum) I can't imagine.

You are forcing you're way of doing things down other people's throats, and
labelling any other way of doing things as "perverse". That's what I see as
fascist.

I am not forcing anyone to do anything, nor do I wish to do so. You
might consider finding someone who's actually lived under a fascist
regime, and see how much sympathy you get for the oppression you've
experienced here.

I criticized you. Grow up and deal with it. Or continue making a
fool of yourself. It's entirely up to you and, fascist that I am, I
wouldn't have it any other way.
 
C

CBFalconer

Frederick said:
Keith Thompson posted:


No confusion.


This is exactly what I'm talking about -- you label my way of
doing things as "perverse", even though it is perfectly OK. The
word "perverse" has negative connotations. If you're looking for a
more neutral word along the same lines, then perhaps try "uncommon".

Furthermore, you conciously introduced me to a newbie in a
disrespectful way -- stating that my methods are "perverse".


You are forcing you're way of doing things down other people's
throats, and labelling any other way of doing things as "perverse".
That's what I see as fascist.

This is totally ridiculous. Using an unconventional word order can
only lead to confusion, which by itself is a strong argument for
not so doing. Perverse is a perfectly good word, usable in polite
company and applicable to many things, including men, women, and
children. Dogs, luckily, are not so likely to be perverse.
However the height of perversity is to blow it up to full sized
religious war, rather than leaving it what it is - a style point.
 
H

Herbert Rosenau

Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET

2. Signed char
[-128 to 0] - ?????
You means -127. -128 can be possible on 2th complement mashines.
[0 to 127] - ASCII CHARACTER SET

What does it mean for a character to be signed ? Is there any
difference between signed and unsigned char ? If Yes, how do they
differ. If No, then why didnt the C standard restrict the char data
type to unsigned alone.

They differ in the same as int and unsigned int or long and unsigned
long differ. The have a sign bit.

The standard names 3 types of char:
char can be signed or unsigned depending on the
environment
unsigned char 0 - 255 no sign bit
signed char -127 - +127
I have been referring to various articles, but in vain. Any help would
be greatly appreciated.

Often signed char is used as short short int to save mempry space.
Sometimes the same for unsigned.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

const unsigned long int i = 5;
int long unsigned i const = 5;
cont int long unsigned i = 5;
int unsigned const long i = 5;

Only 1 of multiple millions programmers use that unconventional
crappyx coding, even as it is legal.
You will find that many C programmers (Keith Thompson included) prefer to
place "unsigned" before the size-specifier, rather than after, i.e.:

unsigned char

I myself prefer a different form:

The only, really only programmer on the whole world I've seen in about
30 years programming in C I've ever seen. You are really perverse as
you are the only one of thousends different sources of thousends
programmers I've sighted yet who is so perserve as you.
char unsigned

The real world uses
unsigned char
instead.
The original poster should note that some programmers may deem as
"perverse", styles which are different from their own -- not unlike how a
heterosexual might deem homosexuality to be perverse.

The original poster should note that any human being who doesn't suffer
from severe mental retardation should be able to understand that "char
unsigned" and "unsigned char" are equivalent.

I suggest to the original poster that he or she write their definitions in
whatever word order they like best.




Better yet, I strongly recommend that you realise that word order is at the
programmers discretion in C.
Better you realises thet there is an unwritten agreement between all C
programmers on the world to use the word order as defined in any
source other than from you.

It is time intensive to understund your crappy order. Time is money,
so even as it costs litte time for a line, it costs a significant
amout of time for a significant number of lines. That time is spended
more effective on real problems than to decode your crap. Stop writing
your at friendiest sayd "unconventional" style but use here in the
groups the convention the rest of the whole world is using.

Would you ever ty to drive on the left side of the street on the
continent only because YOU means that is better than driving on the
right site?

The whole community gives a shit of your style. It uses that what it
is trained in since C is spreaded outside the labs of K&R.

You may use your style for yorself, but stop braking out others with
that.

You are of really no help for beginners but you are confusing them.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 

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
473,951
Messages
2,570,113
Members
46,698
Latest member
alexxx

Latest Threads

Top