From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_40 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 27 Oct 92 01:22:56 GMT From: munnari.oz.au!ariel!ucsvc.ucs.unimelb.edu.au!phillip.edu.au!dale@tcgould. tn.cornell.edu Subject: Re: Uninitialized subtype variables Message-ID: <1992Oct26.202256.13240@phillip.edu.au> List-Id: On the subject of initialisation one problem that I encounter often in teaching CS1 Ada course is that of an out parameter that is not initialized. For example the following search procedure procedure search(x :in string10; key :in character; found: out boolean; index: out string10_range); will set index to a value _only_ if the item is found (why should it do anything else?). If the actual parameter associated with index is subtyped, then not finding 'key' often results in a constraint error. This is particuarly galling when the actual for index is itself not initialised (why should it be?), and (because of the copy in/copy out semantics of scalars) produces the erroneous result in the first place. The _only_ solution for first year students is to say "yes well that is a problem. Why don't you just make it an in out parameter and forget about it" (well, this is almost what I say... :-) ); The other solution is to create a variable with a set/unset field... type result(found :boolean ) is record case found is when false => null; when true => index :string10_range; end case; end record; and then modifying the procedure search accordingly. Certainly simulating return values like this is the pure (but painful) way of maintaining the correct parameter modes for a procedure such as search. ??? Perhaps variables should have a special value (Null) that indicates that they have not been initialised? ??? Perhaps another field could be set aside to maintain the initialisation status *by the compiler* ??? Perhaps a pragma could be provided to disable this useful (development?) feature. Remember the days when array index checking was not the norm? First it came in during program testing, and now during program operation? Will variable initialisation testing follow? --------------------------------------------------------------------------- Dale Stanbrough Royal Melbourne Institute of Technology Melbourne, Australia dale@phillip.edu.au