comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Base64-Encoding
Date: Mon, 15 Oct 2007 11:37:50 -0400
Date: 2007-10-15T11:37:50-04:00	[thread overview]
Message-ID: <wccbqb0gzht.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: yge3awch0ku.fsf@hugsarin.dmusyd.edu

Jacob Sparre Andersen <sparre@nbi.dk> 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 - <result-of-F>'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



  reply	other threads:[~2007-10-15 15:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-15 14:12 Base64-Encoding Stefan Bellon
2007-10-15 14:46 ` Base64-Encoding Jacob Sparre Andersen
2007-10-15 14:54   ` Base64-Encoding Stefan Bellon
2007-10-15 15:14     ` Base64-Encoding Jacob Sparre Andersen
2007-10-15 15:37       ` Robert A Duff [this message]
2007-10-15 15:40     ` Base64-Encoding Jean-Pierre Rosen
2007-10-15 16:39       ` Base64-Encoding Stefan Bellon
2007-10-16 10:42         ` Base64-Encoding Stephen Leake
2007-10-17 14:07           ` Base64-Encoding Stefan Bellon
2007-10-17 15:09             ` Base64-Encoding Adam Beneschan
2007-10-17 18:15               ` Base64-Encoding Larry Kilgallen
2007-10-15 18:24 ` Base64-Encoding Adam Beneschan
2007-10-19  2:43 ` Base64-Encoding anon
2007-10-19  4:33   ` Base64-Encoding anon
2007-10-19  7:35     ` Base64-Encoding Jean-Pierre Rosen
2007-10-19  6:59   ` Base64-Encoding Stefan Bellon
2007-10-19 19:40     ` Base64-Encoding anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox