Usage of INT_MAX, etc.

Jaroslaw Staniek js at iidea.pl
Tue Oct 24 22:54:00 BST 2006


Simon Hausmann said the following, On 2006-10-24 21:30:

>>>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?

OK, I can commit INT_MAX for functions like this, where "the default is at 
least 32-bit maximum" (that's the meaning of INT_MAX).

For other cases, where we need "this value is exactly 32-bit maximum", as 
already mentioned, following standard C++ code is used

  numeric_limit<int32_t>::max()


== Proposal ==

What I now propose is to make docs and function signatures shorter by defining 
  things like

  #define INT32_MAX numeric_limit<int32_t>::max()

within KDElibs. My ratinales:
- it's very similar to standard INT_MAX
- it's already used here and there, e.g. in KDevelop[1] and (I think) in any 
software that must precisely deal with ranges

And at least there's a need for using {32-bit|64-bit|whatever} checks if 
someone adds sanity checks when dealing with binary data or interprets numbers 
written as text (eg. in XML).

Then the developer can write an API documentation like this:

"@return a value smaller than INT32_MAX"

instead of

"@return a value smaller than numeric_limit<int32_t>::max()"


[1] 
http://websvn.kde.org/trunk/KDE/kdevelop/test/cool-lexer.cc?rev=475229&view=auto
-- 
regards / pozdrawiam, Jaroslaw Staniek
  Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
  Kexi & KOffice: http://www.kexi-project.org, http://www.koffice.org
  KDE3 & KDE4 Libraries for MS Windows: http://kdelibs.com, http://www.kde.org




More information about the kde-core-devel mailing list