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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!stanford.edu!bcm!aio!dnsurber
  3. From: dnsurber@lescsse.jsc.nasa.gov (Douglas N. Surber)
  4. Subject: Re: null arrays
  5. Message-ID: <dnsurber.722098125@node_26400>
  6. Sender: news@aio.jsc.nasa.gov (USENET News System)
  7. Organization: Lockheed Engineering and Sciences
  8. References: <BxvtCA.LM1@dale.cts.com>
  9. Date: 18 Nov 92 14:48:45 GMT
  10. Lines: 41
  11.  
  12. In <BxvtCA.LM1@dale.cts.com> jhb@dale.cts.com (John Bollenbacher) writes:
  13.  
  14. >procedure TEST is
  15.  
  16. >  subtype T is NATURAL range 0 .. 10;
  17.  
  18. >  type ARR is array (T range <>) of BOOLEAN;
  19. >  
  20. >  type A(N : T := 0) is record 
  21. >    DATA : ARR(1..N);
  22. >  end record;  
  23. >  I : INTEGER;
  24. >  O : A := (3, (TRUE, FALSE, TRUE));
  25. >  
  26. >  N1 : constant ARR := O.DATA(1..0) & O.DATA(1..0);
  27. >  N2 : constant ARR := O.DATA(1..0) & O.DATA(3..2);
  28.  
  29. N2'first = 3 (LRM 4.5.3 4)
  30.  
  31. >begin
  32. >  I := N1'LENGTH; -- I = 0 
  33. >  I := N2'LENGTH; -- I = 0
  34. >  O := (0, N1);   -- does not raise constraint
  35. >  O := (0, N2);   -- raises constraint
  36.  
  37. O.Data'first /= N2'first thus raises constraint error (LRM 4.3.1 3, 3.3 4)
  38.  
  39. >end TEST; 
  40.  
  41. The trick here is that the constraint error is raised in forming the
  42. aggregate, not in the assignment.  LRM 4.3.1 3 says "A check is made that
  43. the value of each subcomponent of the aggregate _belongs_ to the subtype
  44. of this component."  The magic word is "belongs".  LRM 3.3 4 says "a value
  45. is said to belong to a subtype of a given type if it belongs to the type
  46. and satisfies the constraint." The bounds of N2, i.e. 3 and 2, do not
  47. satisfy the constraint of the aggregate, i.e. in the range 1 .. 0.  If this
  48. were an array assignment rather than an aggregate, it would work.
  49.  
  50. Douglas Surber
  51. Lockheed
  52. Houston, TX
  53.