Posted: Tue Sep 04, 2007 6:59 am
As i said it is just a small enoyance.
That was my point, because uint8_t is defined asSolar wrote:The only place I could think of where the "char-ness" of uint8_t actually makes a difference is exactly your cout example. And let's face it, if your application is primitive enough (not using "primitive" to be derogatory) to use cout for output, you can be expected to do those couple of casts instead of turning half the language inside out to "fix" what is a minor nuisance.
Code: Select all
typedef unsigned char uint8_t;
I believe i have allready answered that question, but basicly im a perfectionist. Yes its true, the use of cout is not the best way of doing things, but i am somewhat inexperienced.pcmattman wrote:I must ask though, what is the context for using such a small type, why not just use a 32-bit integer (unless size is important, in which case I think cout is not the way forward).
This is my last one (I hope)...Zacariaz wrote: Again i do not NEED an 8 bit integer type, it is just curious that it doesnt exist. Again i know that char is an integer type, but it still acts different, and it just seems wrong!
No, cstdint is the standard header for that purpose, with all the contents in namespace STD as they should be.bluecode wrote:And I am aware that stdint.h is not standard C++ as of 2003, but iirc it will be in C++0x.
I think I also read somewhere or saw it somewhere on google video that there will be a way to do strong typedefs, but I am not very sure about this...
Code: Select all
template <class T>
class StrongTypedef {
private:
T _val;
public:
StrongTypedef(const T &val) { _val = val; }
const T &value() { return _val; }
// other operators as required, probably lots
};
typedef StrongTypedef<uint8_t> byte;
[/quote]
Your optimizer will remove this class and just use it as a typedef. I think if you add a back conversion operator it'll break down (since you can ad-hoc convert back & forth, so it won't bother doing the right thing). You can make the constructor explicit but it makes it a bit more tedious.
Because the typedef of uint8_t translates into unsigned char... It's like doing this:Zacariaz wrote:Yes i figured that out by now, but thats not the point. I dont supose it would be hard to get the cout class to treat fx. uint8_t as an 8 bit ingeter instead of a 8 bit char? Why not have both?
Code: Select all
#define uint8_t (unsigned char) // the same as typedef unsigned char uint8_t
Again: It's not "char" that behaves different, it's cout. Because in 99% of the cases you cout a 8-bit-value, you want the character printed, not the value, so that this is the default behaviour.Zacariaz wrote:Again i know that char is an integer type, but it still acts different, and it just seems wrong!
You should be able to add overloads to cout for unsigned and signed chars, as the default char is neither and the three types should be treated as separate (for purposes of name mangling and overloading). I do expect unsigned char to degenerate to char.Solar wrote:Again: It's not "char" that behaves different, it's cout. Because in 99% of the cases you cout a 8-bit-value, you want the character printed, not the value, so that this is the default behaviour.Zacariaz wrote:Again i know that char is an integer type, but it still acts different, and it just seems wrong!