Discussion:
[perl #39855] configuration: define MIN/MAX macros for all integral typedefs
(too old to reply)
Chip Salzenberg
2006-07-17 18:59:47 UTC
Permalink
# New Ticket Created by Chip Salzenberg
# Please include the string: [perl #39855]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39855 >


It's great to have INTVAL and UINTVAL, but without MAX_INTVAL it's kind of
hard to work with them in some respects. All integral typedefs should have
min/max macros. Syntax not a big deal, it can be fixed later, just don't
break anything when introducing them.
--
Chip Salzenberg <***@pobox.com>
Patrick R. Michaud via RT
2008-05-17 21:57:20 UTC
Permalink
Post by Chip Salzenberg
It's great to have INTVAL and UINTVAL, but without MAX_INTVAL it's kind of
hard to work with them in some respects. All integral typedefs should
have
Post by Chip Salzenberg
min/max macros. Syntax not a big deal, it can be fixed later, just don't
break anything when introducing them.
Nothing has happened on this ticket since it was introduced in 2006. Do
we need MIN/MAX macros? If so, why, or where do we expect them to be used?

Pm
Nicholas Clark
2009-04-18 11:17:47 UTC
Permalink
Post by Chip Salzenberg
Post by Patrick R. Michaud via RT
Post by Chip Salzenberg
It's great to have INTVAL and UINTVAL, but without MAX_INTVAL it's
kind of
Post by Patrick R. Michaud via RT
Post by Chip Salzenberg
hard to work with them in some respects. All integral typedefs should
have
Post by Chip Salzenberg
min/max macros. Syntax not a big deal, it can be fixed later, just
don't
Post by Patrick R. Michaud via RT
Post by Chip Salzenberg
break anything when introducing them.
Nothing has happened on this ticket since it was introduced in 2006. Do
we need MIN/MAX macros? If so, why, or where do we expect them to be
used?
Post by Patrick R. Michaud via RT
Pm
#define MAX_UINTVAL (UINTVAL)((INTVAL)-1)
I think that that would be better defined in terms of ~0
Post by Chip Salzenberg
#define MIN_UINTVAL (UINTVAL)0
This one, I think is correct.
Post by Chip Salzenberg
#define MAX_INTVAL (((INTVAL)-1) / 2)
Eh? -1/2 is 0 for signed integer arithmetic.
Post by Chip Salzenberg
#define MIN_INTVAL ((~MAX_INTVAL) + 1)
Even with the correct definition of MAX_INTVAL, that's going to be out by 1.
For a two's complement system, it doesn't need the + 1.

The logic that Perl 5 uses to do this is described here:
http://perl5.git.perl.org/perl.git/blob/HEAD:/perl.h#l2178

I suspect it's portable.

Nicholas Clark
NotFound
2009-04-18 12:45:19 UTC
Permalink
Post by Chip Salzenberg
It's great to have INTVAL and UINTVAL, but without MAX_INTVAL it's kind of
hard to work with them in some respects.  All integral typedefs should
have
Post by Chip Salzenberg
min/max macros.  Syntax not a big deal, it can be fixed later, just don't
break anything when introducing them.
Nothing has happened on this ticket since it was introduced in 2006.  Do
we need MIN/MAX macros?  If so, why, or where do we expect them to be used?
The current intended names for that macros are PARROT_INTVAL_MAX,
PARROT_INTVAL_MIN, and so on.

The last work in this matter is: include/parrot/platform_limits.h
--
Salu2
NotFound
2009-04-23 15:13:18 UTC
Permalink
It looks like those comments in platform_limits.h are out-of-place.
PARROT_INTVAL_MIN and PARROT_INTVAL_MAX are defined in
include/parrot/config.h, although the definition may not be as flexible
as the macros in perl.h that Nicholas mentioned.  It might be beneficial
to incorporate them into what we're currently using, but I'm not a good
judge of that.
The definitions in parrot's config.h come, as one would expect, from
config/auto/format.pm.  (TT #530 addresses this.)  It should be pretty
simple to add the code needed to figure out which macros to use for the
missing min/max values.
platform_limits.h is intended for platforms where there is no limits.h
and the macros must be taken from another include file, or explicitly
defined. Also, when someone wants to build with different integer
types and the detection of appropriate limit values for that types
fails.

config.h conditionally does his own definitions after including
platform_limits. If that definitions do the right thing
platform_limits does not need to do nothing. Consequently, the generic
version does nothing.
--
Salu2
Loading...