Usage of INT_MAX, etc.

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


(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.
#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"
(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 ( to work on
  Kexi & KOffice:,
  KDE3 & KDE4 Libraries for MS Windows:,

More information about the kde-core-devel mailing list