confusion with character types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

confusion with character types

Jochen Wilhelmy
>  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.

-Jochen


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: confusion with character types

bruce.r.stephens
Jochen Wilhelmy <[hidden email]> 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.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev