Use int type or qint32 as a loop iterator
-
wrote on 19 Feb 2020, 00:06 last edited by
Hi,
More philosophical question.
As far as I know Qt standard types like quint16, qint32, qin64 etc guarantee that it take 2, 4 and 8 bytes respectively to store every number on any type of machine.
But there is standart loop like:for (int i; i < 100; i++){ //body of loop }
that is usually written with iterator type int (in every code). Usually it is not a problem if on a developer computer type int is a 4-byte integer and on another it may take 8 bytes (are there such situations?). But from the side of politeness to other developpers is it ok to write loops with Qt stadart types ?? like:
for (qint32 i; i < 100; i++){ //body of loop }
I'm sorry if I don't fully understand the difference between int and qint32
-
@Please_Help_me_D said in Use int type or qint32 as a loop iterator:
I'm sorry if I don't fully understand the difference between int and qint32
There isn't a difference.
-
Hi,
More philosophical question.
As far as I know Qt standard types like quint16, qint32, qin64 etc guarantee that it take 2, 4 and 8 bytes respectively to store every number on any type of machine.
But there is standart loop like:for (int i; i < 100; i++){ //body of loop }
that is usually written with iterator type int (in every code). Usually it is not a problem if on a developer computer type int is a 4-byte integer and on another it may take 8 bytes (are there such situations?). But from the side of politeness to other developpers is it ok to write loops with Qt stadart types ?? like:
for (qint32 i; i < 100; i++){ //body of loop }
I'm sorry if I don't fully understand the difference between int and qint32
@Please_Help_me_D like @Christian-Ehrlicher said, there is no real difference,
but most access functions, like for example QVector::at(int), expect an int.So you will get a warning, when using the variable inside the loop, in such a fashion, and you'll have to cast it, to silence the warning.
-
wrote on 19 Feb 2020, 11:29 last edited by
@Christian-Ehrlicher and @J-Hilk thank you!
-
wrote on 20 Feb 2020, 02:33 last edited by
If coding for the platform then it's ok to use the Qt types. If the function is more generic then use the equivalent standard types. As for myself: I generally use standard types even if Qt aliases them.
2/5