Usage of INT_MAX, etc.

David Faure faure at kde.org
Wed Oct 25 12:13:33 BST 2006


On Wed Oct 25 2006, Simon Hausmann wrote:
> On Tuesday 24. October 2006 21:22, Jaroslaw Staniek wrote:
> > Simon Hausmann said the following, On 2006-10-24 21:02:
> > > On Tuesday 24. October 2006 20:27, Jarosław Staniek wrote:
> > >>Hello,
> > >>
> > >>(I). The problem
> > >>
> > >>I propose to use macros like INT_MAX instead of 2147483647, and so on in
> > >>KDE code. For instance, KInputDialog uses hardcoded numbers like
> > >>2147483647:
> > >>
> > >>int KInputDialog::getInteger (const QString & caption,
> > >>		const QString &  	label,
> > >>		int  	value = 0,
> > >>		int  	minValue = -2147483647,
> > >>		int  	maxValue = 2147483647,
> > >>[..]
> > >>
> > >>INT_MAX, INT_MIN, ULLONG_MAX, etc. is defined within POSIX in limits.h.
> > >>I noticed Qt (qinputdialog.h) does not use it. My suspect is that values
> > >>like INT_MAX are not hardware-independent, while the API has to be
> > >> portable at source code level. So maybe using INT_MAX and friends is not
> > >>recommended? I may be wrong but so far I found two rules:
> > >
> > > From Qt's perspective INT_MAX and friends are perfectly fine. Don't look
> > > at qinputdialog.h as reference :). limits.h is included in various public
> > > header files and for example qlayoutitem.h uses INT_MAX.
> > >
> > > I don't think another level of indirection buys us anything here :)
> >
> > So if this is the case, could we switch to INT_MAX, etc. in methods like
> > KInputDialog::getInteger(), to allow developers passing the default values
> > a bit easier (by writing INT_MAX instead of copying/pasting 2147483647 in
> > every place when they want to e.g. specify 'QWidget* parent' arg?
> 
> I don't get the 'QWidget* parent' part 

The real problem is that the typical use of getInteger() (passing a parent widget but
not specifying any min/max) requires to give values to minValue and maxValue.

There should be an overload that only takes a caption and a QWidget* (since making 
it first is against the rules in Qt API AFAIK).

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list