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
>But would it be better if this gave a different result?
>
> signed char n = '\n';
> std::cout<<  "Hello world"<<  n;

of course ;-)
these are equivalent:
signed char n = '\n';
int8_t n = '\n';
int8_t n = 10;

therefore I would expect "Hello world10".

it's the same as this being different:
float n  = '\n';
std::cout<<  "Hello world"<<  n;


_______________________________________________
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:

>>But would it be better if this gave a different result?
>>
>> signed char n = '\n';
>> std::cout<<  "Hello world"<<  n;
>
> of course ;-)
> these are equivalent:
> signed char n = '\n';
> int8_t n = '\n';
> int8_t n = 10;
>
> therefore I would expect "Hello world10".
>
> it's the same as this being different:
> float n  = '\n';
> std::cout<<  "Hello world"<<  n;

Perhaps, though I tend to think (apparently not entirely correctly) of
"char" as being equivalent to either "signed char" or "unsigned char".

In any case there's nothing that clang/libcxx ought to do.  The standard
is what it is.  (Perhaps a stream which handles signed and/or unsigned
chars differently would be useful and that seems like a plausible
extension, but I doubt it's really worth adding.)
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev