[Development] Best practice for defining an integer constant

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Fri Feb 14 11:29:28 CET 2014


I have a need for defining an integer constant that'll be used for
initializing a member variable of a private class.

The Qt coding conventions (http://qt-project.org/wiki/Coding-Conventions)
recommend using an enum over 'const int'.

The rationale given there is that an enum will be replaced at compile-time
resulting in 'faster code'. Won't that be the case with 'const int' as
well? I think a 'const int' will be inlined in the code. CMIIW.

Also, there are a couple of instances in our current code where such
(static and non-static) constants are used. Whats the recommended way?

Thanks,
-mandeep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140214/0164cc00/attachment.html>


More information about the Development mailing list