[cfe-dev] confusion with character types

Bruce Stephens bruce.r.stephens at gmail.com
Thu Oct 14 07:02:34 PDT 2010


Jochen Wilhelmy <j.wilhelmy-KvP5wT2u2U0 at public.gmane.org> writes:

>>  That seems to me to be the better interpretation.  Specifically, it
>>  would be surprising (to me) if
>>
>>	std::cout<<  "Hello world"<<  '\n';
>>
>>  caused "Hello world10" to be displayed.
>
> Your reply shows that the topic is indeed confusing.  As '\n' in your
> example is of type char and neither of type signed char nor of type
> unsigned char, it would result in the correct output ("Hello world\n")
> even if signed char (int8_t) and unsigned char (uint8_t) are treated
> as numbers.

But would it be better if this gave a different result?

	signed char n = '\n';
	std::cout << "Hello world" << n;

(or s/signed/unsigned/)

That seems just as peculiar, though I guess I could go for "unsigned
char" being different; actually it would be quite convenient for my code
if that displayed as hex.



More information about the cfe-dev mailing list