PDA

View Full Version : The best way to write compatible platform data format ?



tonnot
15th November 2011, 07:48
Have I to rewrite all the code using types for this purpose (qint32, etc)
Is there some macro or directive to to this work automatically ?
Maybe I'm looking something impossible ?
Thanks

Lykurg
15th November 2011, 08:26
Hmm, QtCreator search and replace in all project files? Should do the trick.

tonnot
15th November 2011, 09:58
Thanks ly.
It has a problem ? (change using qtcreator , i think ... ), all my simple vars used at for loops (in example) are going to changed ... I dont know if I need to do this.

And I have a doubt : can I compare or use a standard and QT typedefs ? In example :

int my_var_int;
qint my_var_qint;
if (my_var_int > my_var_qint) ....
my_var_qint+=my_var_int;
etc ...

And, what can I expect about the performance of my app ? That is, a windows app with int, double, etc are going to be faster than other that uses qint, qreal, etc. ?
Maybe better to write a code to translate data from one platform to another instead of having the whole app multi-platform writed ? (I'm talking about binary data files or streams ).
Thanks.

Oleg
15th November 2011, 10:22
Your program won't be faster, but you also won't get troubles with platform type differences. The best way to write cross-platform application is to have the same code for all platforms ;)

tonnot
15th November 2011, 10:29
Yes, but I'm talking about types...
Thanks

Lesiok
15th November 2011, 12:23
Thanks ly.
And, what can I expect about the performance of my app ? That is, a windows app with int, double, etc are going to be faster than other that uses qint, qreal, etc. ?Nothing. All Qt types are C typedefs. So for the compiler there is no difference whether you write qint32 or signed int because it is defined qint32.

tonnot
15th November 2011, 12:48
All Qt types are C typedefs. So for the compiler there is no difference whether you write qint32 or signed int because it is defined qint32.
So.... Have I or not to write my code using qt typedefs ?
And a last question, the endianness is not fixed using qt typedefs isn't it ?
Thanks

MarekR22
15th November 2011, 12:51
QDataStream

marcvanriet
22nd November 2011, 23:46
For example : on smaller processors an int - might - be 16 bits instead of 32 bits, and then your programs won't work if you really need the 32 bits. And on a 64-bit processor, your program - might - behave differently if you rely on the 'overflow' of your numbers (e.g. If you expect that if you add 1 to 0xFFFFFFFF that you get 0x00000000).

But in many cases the C types have the same size for different platforms. I say 'many', not 'most' or 'all', so if you really want to be safe, then you should use qint etc.

Endianess is determined by the processor architecture. It is transparent to you (unless you start packing values in binary arrays, for which you should use QDatastream).

Regards,
Marc