home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / ada / 2163 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  1.4 KB

  1. Path: sparky!uunet!ogicse!henson!news.u.washington.edu!milton.u.washington.edu!mfeldman
  2. From: mfeldman@milton.u.washington.edu (Michael Feldman)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: initialization of vars when declared.
  5. Message-ID: <1992Jul21.192624.29154@u.washington.edu>
  6. Date: 21 Jul 92 19:26:24 GMT
  7. Article-I.D.: u.1992Jul21.192624.29154
  8. References: <1992Jul21.053439.29957@iitmax.iit.edu>
  9. Sender: news@u.washington.edu (USENET News System)
  10. Organization: University of Washington, Seattle
  11. Lines: 28
  12.  
  13. In article <1992Jul21.053439.29957@iitmax.iit.edu> janiadi@elof.iit.edu (Aditya Jani) writes:
  14. >
  15. >How can one initialise values when variables are declared
  16. >as in 'C' :
  17. >    int a_variable[3] = {1, 2, 3};    ?
  18. >
  19.         A_Variable: ARRAY(1..3) OF Integer := (1,2,3);
  20.  
  21. The simple cases are just like C. On the other hand, try
  22.  
  23.         Another_Var: ARRAY(X..Y, W..Z) OF Integer :=
  24.                        (OTHERS => (OTHERS => 0));
  25.  
  26. As long as X,Y,Z, and W have values when this declaration is
  27. elaborated, the whole matrix is initialized with one statement.
  28.  
  29. To add fuel to the fire, the initializing value can be computed:
  30.  
  31.         Another_Var: ARRAY(X..Y, W..Z) OF Integer :=
  32.                        (OTHERS => (OTHERS => Integer(Sqrt(Q))));
  33.  
  34. Don't try this at home - you won't like the exception propagation
  35. if Q is negative and Sqrt raises an exception about it...
  36.  
  37. The point is that initialization is (generally) intuitively easy.
  38.  
  39. Mike Feldman
  40.