Usage of INT_MAX, etc.
Jaroslaw Staniek
js at iidea.pl
Wed Oct 25 09:20:10 BST 2006
Simon Hausmann said the following, On 2006-10-25 08:00:
> On Wednesday 25. October 2006 00:28, Thiago Macieira wrote:
>
>>Jaroslaw Staniek wrote:
>>
>>>What I now propose is to make docs and function signatures shorter by
>>>defining things like
>>>
>>> #define INT32_MAX numeric_limit<int32_t>::max()
>>
>>Only in docs.
>>
>>Don't define that in C++ code, since that requires int32_t, which isn't
>>always present. It also requires #include <limits> and "using namespace
>>std;"
>>
>>Also note that you don't need to define INT32_MAX to a call to
>>numeric_limit::max. For 32 bits exactly, MAX is (2^31)-1 and MIN
>>is -(2^31).
>>
>>So I feel this #define is unnecessary.
>
>
> I agree with Thiago. I don't see what problem it actually solves, since int is
> 32 bit on all platforms we support.
I am sorry, I'd like to talking about all the integer datatypes (hence the
"etc." in the "Usage of INT_MAX, etc." subject), and maybe floating point
(long double) is also affected. Sorry about choosing wrong example. Talking
about 'long's is better.
So: sizeof(long) is 8 under IA64 and 4 under powerpc (KDE is available there
on Linux and will be on MacOSX)
i.e. LONG_MAX/LONG_MIN/ULONG_MAX/ULONG_MIN are affected. I haven't checked all
the combinations yet.
Since the only constraint is that LONG_MAX >= 2147483647, LONG_MAX >= INT_MAX,
this could help:
#define LONG32_MAX 2147483647L
Earlier I proposed INT32_MAX, etc. for completness, and to increase
self-commenting code (in places where # of bits is important).
That said, I am OK with having above defines in my local code, at least for
some time, if this is the answer.
The main reason I'd like to have it is to get clearly defined limits for
applications that allows the user to select data types (Kexi is one of them,
and various database environments are other) - otherwise it is even risky to
fetch the data from the database/file.
--
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