Peter Nilsson wrote On 07/11/07 22:06,:
Eric Sosman said:
-- can you think of even one deleterious consequence of
'A' being an int?
I think '\xfe' having 4 different values is more of a
concern to me that it's type. [...]
'\xfe' is always 254 on systems where the behavior is
defined, that is, on systems where CHAR_MAX >= 254. On
other systems the behavior is undefined and there's no
reason to restrict the outcome to just three other values.
Could be any value at all, or nasal demons.
Argument for undefinedness:
6.4.4.4p6 says "[...] The numerical value of the
hexadecimal integer so formed specifies the value of
the desired character or wide character." The specified
value is therefore 254.
6.4.4.4p10 says "[...] If an integer character constant
contains a single character or escape sequence, its value is
the one that results when an object with type char whose
value is that of the single character or escape sequence is
converted to type int." Hence, the value of '\xfe' is the
result of converting a char object with value 254 to int.
On a system where CHAR_MAX < 254 no char object can
have the value 254, so 6.4.4.4p10 does not specify the
value of '\xfe' on those systems.
4p2 says "[...] Undefined behavior is otherwise
indicated [...] by the omission of any explicit definition
of behavior. There is no difference in emphasis among these
three; they all describe ``behavior that is undefined.''"
Since the derivation of an int value from '\xfe' is not
explicitly defined when CHAR_MAX < 254, the behavior is
undefined.
Observation: The int-ness of character constants is not
to blame for this situation. If they were of type char and
the conversion language were deleted from 6.4.4.4p10, you'd
still be stuck with the fact that no char can have a value
greater than CHAR_MAX. The value of '\xfe' (if it has one)
is not germane to the debate over character constants' types.