comp.lang.ada
 help / color / mirror / Atom feed
* Implementing an elegant range type.
@ 2001-03-19 17:45 Chad R. Meiners
  2001-03-19 18:38 ` Mark Lundquist
  2001-03-21 22:55 ` Implementing an elegant range type Chad R. Meiners
  0 siblings, 2 replies; 13+ messages in thread
From: Chad R. Meiners @ 2001-03-19 17:45 UTC (permalink / raw)


There are certain times that I have wanted to pass ranges as a
parameter to subroutines, for example being able to
write, "Register_Slots (75..4242);" which of course isn't directly
allowed.  The solution I came up with is to declare a null type that
doesn't take up any memory so that I can create array type of the
ranges I want as in the example below.

type Nothing is null record;
for  Nothing'Size use 0;

type Integer_Range_Type is array (Integer range <>) of Nothing;

Thus I could declare an array, "Integer_Range : Integer_Range_Type
(Integer);", and use it to pass array slice which would contain the
range data.  Example: "Register_Slots (Integer_Range(75..4242));"

The problem I am encountering is that when I declare a variable
with a range as large as Integer_Range's I get a
Storage_Error which doesn't make much sense since if Integer_Range's
range is something smaller than 2**20 elements, Integer_Range'Size
equals 8 for all cases which I expect should be true even for the
large cases since the elements of the array have no size.  I am
using GNAT 3.13p on WinNT.

Has anyone used a similar approach for representing ranges or have
any advice on getting around the Storage_Error for large ranges?

Thank you,
-Chad R. Meiners





^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2001-03-28 22:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-19 17:45 Implementing an elegant range type Chad R. Meiners
2001-03-19 18:38 ` Mark Lundquist
2001-03-19 20:50   ` Chad R. Meiners
2001-03-22 22:20     ` Nick Roberts
2001-03-23 22:29       ` Brian Rogoff
2001-03-20  4:48   ` Dr Adrian Wrigley
2001-03-20 15:31     ` Robert A Duff
2001-03-21  1:21       ` Dr Adrian Wrigley
2001-03-21  3:58         ` Brian Rogoff
2001-03-22 23:00         ` Array 'downto' [Was: Implementing an elegant range type] Nick Roberts
2001-03-26 18:28           ` Stephen Leake
2001-03-28 22:35           ` Robert A Duff
2001-03-21 22:55 ` Implementing an elegant range type Chad R. Meiners

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox