home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / ada / 3300 < prev    next >
Encoding:
Text File  |  1992-11-18  |  1.6 KB  |  53 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!aplcen.apl.jhu.edu!ddsdx2.jhuapl.edu!dlc
  3. From: dlc@ddsdx2.jhuapl.edu (Dave Collard x7468)
  4. Subject: Re: null arrays
  5. Message-ID: <1992Nov18.132253.17081@aplcen.apl.jhu.edu>
  6. Sender: news@aplcen.apl.jhu.edu (USENET News System)
  7. Organization: Johns Hopkins University
  8. References: <BxvtCA.LM1@dale.cts.com>
  9. Distribution: usa
  10. Date: Wed, 18 Nov 92 13:22:53 GMT
  11. Lines: 40
  12.  
  13. In <BxvtCA.LM1@dale.cts.com> jhb@dale.cts.com (John Bollenbacher) writes:
  14.  
  15. >Can somebody shed some light on the symptoms of the following program.  In 
  16.  
  17. >-------------------cut here-----------------------------------------------
  18. >procedure TEST is
  19.  
  20. >  subtype T is NATURAL range 0 .. 10;
  21.  
  22. >  type ARR is array (T range <>) of BOOLEAN;
  23. >  
  24. >  type A(N : T := 0) is record 
  25. >    DATA : ARR(1..N);
  26. >  end record;  
  27. >  I : INTEGER;
  28. >  O : A := (3, (TRUE, FALSE, TRUE));
  29. >  
  30. >  N1 : constant ARR := O.DATA(1..0) & O.DATA(1..0);
  31. >  N2 : constant ARR := O.DATA(1..0) & O.DATA(3..2);
  32.  
  33. -- The result of concatenation of a null array and another array is
  34. -- an array with the range of the second array.  Thus N1 has a range
  35. -- of 1..0 and N2 has a range of 3..2.  
  36.  
  37. >begin
  38. >  I := N1'LENGTH; -- I = 0 
  39. >  I := N2'LENGTH; -- I = 0
  40. >  O := (0, N1);   -- does not raise constraint
  41. >  O := (0, N2);   -- raises constraint
  42.  
  43. -- Given the above, this is the common sliding error.  An aggregate assignment
  44. -- does not "slide" the indices to match the constraints of the array in your
  45. -- record.  Since N1'First is 1, no problem.  N2'First is 3 so it does
  46. -- not match 1..N.
  47.  
  48. >end TEST; 
  49.  
  50. --Thor
  51. collard@capsrv.jhuapl.edu
  52. dlc@ddsdx2.jhuapl.edu
  53.