Arithmetic with char variables in TTree

I have char variables in TTree, which are just small integers and I normally type cast them into integers after reading in from the tree. I wonder if I can do arithmetic without type casting and save some memory/CPU ?

I hear that C/C++ always does operations on shorts or chars by type casting to integers first. Is it true ?

Not that I know of.

A priori yes you can.

Cheers,
Philippe.

whenever I use case or cout or some function that wants integer argument I have to type cast chars to integers explicitly. This is very inconvinient.

For example to see value of variable a:

char a = 1;

cout << a << endl; // gives you nothing

// you have to do

cout << int(a) << endl;

this is why I just type cast the variable once and for all.

in this respect it would be nice to have new data type for 1 byte integer, say, Mini_t

similar to Short_t which is 2 byte integer.

I wonder why isn’t it basic built in type anyway ?

char a = 1; cout << a << endl; // gives you nothing As far as cout is concerned (and this is C++) a char is an ASCII character. So if you were to do

char a = 's'; cout << a << endl; // gives you nothing this would print an ‘s’.

cout << int(a) << endl; is the proper syntax and does incur an real performance penalty (that I know of).

[quote]in this respect it would be nice to have new data type for 1 byte integer, say, Mini_t
[/quote]If you make it works in a reasonable way, please let us know.

[quote]whenever I use case …
[/quote]I do not see this problem

Cheers,
Philippe.