[Qt-interest] When to use QT primitives ?

Marco Borm qt-lists at retrodesignfan.eu
Sun May 24 15:14:37 CEST 2009


Simple answer: Because it is not the same. qint32 can hold 32bits on 
every platform, int not.

Complex reason:
Even typical int is 32bit there are platforms where int is 16bit or 
64bit. So if you use int you have to check yourself how many bits it can 
hold on every platform your compile your application. The same for every 
other primitive data type. This makes it nearly impossible to directly 
use the primitive data types for portable network communication.
For that reason nearly every compiler provides non standard fixed length 
types like __int32 on MSVC.

"ISO/IEC 9899:1990, Programming Languages - C (ISO C) left the 
definition of the *short int*, the *int*, the *long int*, and the 
*pointer* deliberately vague to avoid artificially constraining hardware 
architectures that might benefit from defining these data types 
independent from the other. The only constraints were that *int*s must 
be no smaller than *short*s, and *long*s must be no smaller than *int*s, 
and *size_t* must represent the largest unsigned type supported by an 
implementation. It is possible, for instance, to define a *short* as 16 
bits, an *int* as 32 bits, a *long* as 64 bits and a *pointer* as 128 
bits. The relationship between the fundamental data types can be 
expressed as:

/sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) = 
sizeof(size_t)"/


Marco

Kosta wrote:
> One simple question. Why to use QT Primitives, i.e. qint32 instead of 
> int ?
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 4098 (20090522) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   




More information about the Qt-interest-old mailing list