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