Usage of INT_MAX, etc.

Jarosław Staniek js at iidea.pl
Tue Oct 24 19:27:21 BST 2006


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:

1. LSB for libs defines look solid, i.e. hardware independent.
http://www.freestandards.org/spec/booksets/LSB-Core-generic/LSB-Core-generic/libc-ddefs.html
#define INT_MAX	2147483647

2. OTOH, The Open Group mentions just that:

"INT_MAX - Maximum value of an int. Minimum Acceptable Value: 2 147 483 647"

http://opengroup.org/onlinepubs/007908799/xsh/limits.h.html
(what can break behaviour of an app that depends on the max/min values)


(II). The proposal

What about having well defined K_INT_MAX, and so on? Then K_INT_MAX will mean 
always the same value.

At least I widely use quint64 types (former Q_ULLONG) in a database code and 
having the constants defined could help later when more code using it is 
shared in KDE.

Other example:
#define K_UINT64_MAX (quint64)0x080000000

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