comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada and string literals
Date: Fri, 01 Feb 2013 15:22:09 -0500
Date: 2013-02-01T15:22:09-05:00	[thread overview]
Message-ID: <wccsj5fokcu.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1l8gd32wspyy5$.1u81easl2psqm$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Fri, 01 Feb 2013 08:20:24 -0500, Stephen Leake wrote:
>
>> That's what "+" is for:
>> 
>>    function "+" (Item : in String) return access constant String
>>    is begin
>>       return new String'(Item);
>>    end "+";
>> 
>>      Colors : constant String_Sequence :=
>>          (+"red", -- This _is_ Ada!
>>           +"orange",
>>           +"dark green",
>>           ...);
>
> What about:
>
>    function "&" (Left, Right : String) return String_Sequence is
>    begin
>       return (new String'(Left), new String'(Right));
>    end "&";
>
>    function "&" (Left : String; Right : String_Sequence)
>       return String_Sequence is
>    begin
>       return String_Sequence'(1 => new String'(Left)) & Right;
>    end "&";
>
>    Colors : constant String_Sequence := "red" & "orange" & "dark green";

Looks dangerous to me.  If I'm not mistaken, you have a bug:  ;-)
the above sets Colors to a 2-element array containing a pointer
to "redorange" and a pointer to "dark green".  The first "&" in Colors
calls the predefined String one, and the second "&" calls the first
"&" body shown above.  The second body is never called.

I suppose that could be fixed, but we're getting further and
further from something where the compiler is likely to generate
a statically-allocated table of pointers to statically-allocated
strings.

- Bob



  reply	other threads:[~2013-02-01 20:22 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-30  0:44 Ada and string literals codeallergy
2013-01-30  7:08 ` Niklas Holsti
2013-01-30 11:50   ` Mart van de Wege
2013-01-30 13:52     ` Niklas Holsti
2013-01-30 16:09       ` Adam Beneschan
2013-02-01  0:54       ` Shark8
2013-02-01  9:03         ` Niklas Holsti
2013-02-01 14:58           ` Shark8
2013-01-30 16:52     ` codeallergy
2013-01-30 17:19       ` Adam Beneschan
2013-01-30 20:02       ` Simon Wright
2013-01-30 20:19         ` Georg Bauhaus
2013-01-30 22:06       ` Robert A Duff
2013-01-30 22:10         ` Jeffrey Carter
2013-01-31  2:23           ` Robert A Duff
2013-01-31 15:49             ` Adam Beneschan
2013-01-31 22:24               ` Robert A Duff
2013-02-01 21:16       ` gautier_niouzes
2013-02-02  1:55       ` Stephen Leake
2013-02-02 14:30         ` Robert A Duff
2013-01-31  9:20     ` ake.ragnar.dahlgren
2013-01-30 16:20   ` Robert A Duff
2013-02-01 13:20     ` Stephen Leake
2013-02-01 14:49       ` Robert A Duff
2013-02-01 17:23       ` Dmitry A. Kazakov
2013-02-01 20:22         ` Robert A Duff [this message]
2013-02-01 22:03           ` Dmitry A. Kazakov
2013-01-30 22:54 ` codeallergy
2013-02-01  0:50 ` Shark8
replies disabled

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