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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e710f7d3f890e76b X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Base64-Encoding Date: Mon, 15 Oct 2007 11:37:50 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <20071015161229.3f439230@cube.tz.axivion.com> <20071015165435.0eef160d@cube.tz.axivion.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1192462672 21114 192.74.137.71 (15 Oct 2007 15:37:52 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 15 Oct 2007 15:37:52 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:BvwuIrtG1kn71MC9HPa5k7tDG04= Xref: g2news2.google.com comp.lang.ada:2454 Date: 2007-10-15T11:37:50-04:00 List-Id: Jacob Sparre Andersen writes: > Stefan Bellon wrote: >> On Mon, 15 Oct, Jacob Sparre Andersen wrote: > >>> Padded_Data : String (1 .. Padded_Length) := Data & (others => >>> ASCII.NUL); >>> >>> would work fine. >> >> This results in: >> >> error: "others" choice not allowed here > > I can't figure out why, ... Because Ada allows "others" only when the context determines the bounds of the array: X : String (1..10) := (others => '*'); -- OK, bounds of others come from X Y : String := (1..10 => '*'); -- OK, bounds of Y come from aggregate Z : String := (others => '*'); -- Illegal (what is Z'Length?) The right-hand parameter of the "&" function is of subtype String, which is unconstrained, so you can't pass an others-aggregate to it. I suppose the language COULD have been defined to allow it, by special-casing the predefined "&". Allow one (but not both) parameters of "&" to have others, but only if the "&" operator appears in an appropriate context: A : String := "Hello"; function F(X : Integer) return String; B : String (1..100) := A & (others => '*') & F(123); -- Illegal. Requiring the generated code to calculate the bounds of others as B'First + A'Length .. B'Last - 'Length. Yuck -- that works for "&", but not for user-defined functions. Sounds like a complicated rule, for little benefit, since as you point out, it's not that hard to calculate the bounds explicitly: >... but here's something which does work: > > Padded_Data : String (1 .. Padded_Length) := > Data & (Data'Length + 1 .. Padded_Length => ASCII.NUL); - Bob