Byte data type, is it data type?
-
Dear all,
I'm working on port a qt project to standard C++, every Qt data type that i use F2 shortcut has a typedef in qt header files, but didn't found byte data type? what's equivalent of byte in C ?
-
unsigned char or char ?
-
well, a byte is a byte, 8 bits, whether it will be encoded as a signed or unsigned number. You may have noticed QByteArray has utility functions to convert the byte array to unsigned short, int, long and long long.
I don't recall there being a QByte typedef, so a byte is... a raw byte, merely a binary representation. A byte will yield a different value depending on whether you read is as a signed or unsigned char.
-
So, it's an unsigned char, thank you.
-
In the Windef.h file the BYTE is equal to the unsigned char. To make it cross-platform you might want to use the quint8 definition instead. Qt will make sure that it will always be 8 bits in the variable for all supported platforms.
The BYTE will not be a big problem, but if you want to do the same for the int you might encounter strange things. A int could be a different size for any platform being 16, 32 or 64 bits wide!! Int is the default calculating variable of the platform. Using the quint16 or quint32 will make sure you always have enough bits to work with.
When porting the Qt files to a different compiler you are able to include a "typedef.h" converting the quint8 definition etc to a standard C++ type.
Greetz and hope this helps