Why would anyone write int(qRound(x)) ?
-
In the legacy codebase I'm working on (dating from Qt 4.8.7 or earlier) I often encounter statements similar to the following:
int y = int(qRound(x));Looking at the Qt 5 documentation for
qRoundat https://doc.qt.io/qt-5/qtglobal.html I see thatqRound's return type isint. So why on earth would anyone useint(qRound(x))instead of justqRound(x)? Would there be a good reason for this? Maybe historically? HasqRoundalways had a return type ofint? I'm planning to refactor this and remove theint(.), but first would like to get a second opinion on whether there are pitfalls that I'm not thinking of... -
it has always been an int since before the release of Qt 4.8.7
I think that cast is there as a refuse from the STL (std::round(double)returns a double) and your compiler optimises it away in any caseThanks for confirming. I'll remove the int(.) and go on with my life ;-)