From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,502eafcf316bcb10 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-12 11:12:00 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!spool.mu.edu!uwm.edu!lll-winken.llnl.gov!noc.near.net!inmet!dsd!bobduff From: bobduff@dsd.camb.inmet.com (Bob Duff) Subject: Re: Ada can't initialize (aggregate) array of length 1? Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <1994Dec12.081230.24978@roxi.rz.fht-mannheim.de> <3chh6i$lp7@cnj.digex.net> Date: Mon, 12 Dec 1994 18:35:28 GMT Date: 1994-12-12T18:35:28+00:00 List-Id: In article <3chh6i$lp7@cnj.digex.net>, Gentle wrote: >On Mon, 12 Dec 94 08:12:30 CET, Dirk Zoller (duz@roxi.rz.fht-mannheim.de) wrote: >: Simplified I did this: > >: type stone is array (1..2) of character; >: shapes: constant array (1..1) of stone := ("[]"); >: ____________________________________________^ Yes, this is an annoyance. You can't write a one-element positional aggregate in Ada. Nor a zero-element aggregate. To use a one-element aggregate, you have to use named notation, as in: Shapes: constant array(1..1) of Stone := (1 => "[]"); Or: Shapes: constant array(1..1) of Stone := (others => "[]"); > You're trying to squash a string of length 2 into a character space. No, stone is a string of length two, and the string literal is of length two, so that part of it is OK. The only thing wrong with the original example is that it tries to use positional notation for a one-element aggregate, which is not allowed -- named notation is required. >Try initializing like this: > > shapes: constant array (1..1) of stone := (1 => ('[',']')); ^^^^^^^^^ This will work, but you can use the string literal there instead, if you want. >Although type stone could have been declared as a subtype of STRING of >length 2, then your initialization would have worked. String literals work for all string types. A string type is any one-dimensional array type whose element type is a character type. You don't have to use the predefined type String in order to use string literals. The reason for the aggregate restriction is that it would be difficult for compilers to determine whether: ( exp ) is a parenthesized expression of some type, or an aggregate of an array type. If Ada had used some other notation for aggregates (say, [...]), then this problem would not exist. However, I believe the original requirements for Ada forbade using certain Ascii characters, like [ and ], because those characters were not available on all hardware and certain characters are used for different purposes in certain countries that have addition letters not in Ascii. It's still an annoyance not to have a clean notation for zero and one element aggregates. - Bob -- Bob Duff bobduff@inmet.com Oak Tree Software, Inc. Ada 9X Mapping/Revision Team (Intermetrics, Inc.)