M
mdh
Could I get some help understanding a concept that is related to
exercise 4-9 in K&R II. The question relates to the properties of "EOF"
and the issue of transformation from Char to Int. On page 43 or K&R,
(last paragraph) it says "There is one subtle point about the
conversion of characters to integers. The language does not specify
whether variables of type char are signed or unsigned quantities......"
Then goes onto explaining how different machines might convert a char
to a pos or neg integer. But, then it says, (p 44, 1st paragraph) "The
definition of C guarantees that any character in the machine's standard
printing character set will never be negative, so these characters
will always be positive quantities in expressions. But arbitrary bit
patterns stored in character variables may appear to be negative on
some machines, yet positive on others"
I am clearly missing something. The answer to the exercise simply had
the "push-back" characters stored in an array of type "integer" as
opposed to type "character", but even though I see this, the above
explanation has left me more confused than enlightened!
thanks in advance.
exercise 4-9 in K&R II. The question relates to the properties of "EOF"
and the issue of transformation from Char to Int. On page 43 or K&R,
(last paragraph) it says "There is one subtle point about the
conversion of characters to integers. The language does not specify
whether variables of type char are signed or unsigned quantities......"
Then goes onto explaining how different machines might convert a char
to a pos or neg integer. But, then it says, (p 44, 1st paragraph) "The
definition of C guarantees that any character in the machine's standard
printing character set will never be negative, so these characters
will always be positive quantities in expressions. But arbitrary bit
patterns stored in character variables may appear to be negative on
some machines, yet positive on others"
I am clearly missing something. The answer to the exercise simply had
the "push-back" characters stored in an array of type "integer" as
opposed to type "character", but even though I see this, the above
explanation has left me more confused than enlightened!
thanks in advance.