comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada and string literals
Date: Wed, 30 Jan 2013 11:20:17 -0500
Date: 2013-01-30T11:20:17-05:00	[thread overview]
Message-ID: <wccboc6hcce.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: amrv6sFbs48U1@mid.individual.net

Niklas Holsti <niklas.holsti@tidorum.invalid> writes:

> On 13-01-30 02:44 , codeallergy wrote:
>> hi comp.lang.ada, 
>> 
>> question from a newcomer: Why ada does not allow using a string
>> literal with access type ?
>>
>> abc : access string := "LITERAL"; -- error.
>
> Because, unlike C, Ada does not confuse arrays with pointers.
>
> This is the closest Ada equivalent:
>
>    Literal : aliased constant String := "LITERAL";
>    abc     : access constant String := Literal'Access;

That works, but this seems like a closer equivalent to me:

    Abc : access constant String := new String'("LITERAL");

Ada ought to allow:

    Abc : access constant String := "LITERAL"'Access;

with or without the "constant", as a shorthand for the above.

Suppose you want an array of strings.  Well, you can't have
one in Ada, except in the unusual case where they all happen
to have the same length.  So you use array of access to string.

    Colors : constant String_Sequence :=
        ("red"'Access, -- This is not Ada!
         "orange"'Access,
         "dark green"'Access,
         ...);

That gets pretty tedious if you declare a name for each color.

I'd allow arrays of Strings, though, but that's even less Ada-like.

- Bob



  parent reply	other threads:[~2013-01-30 16:20 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 [this message]
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
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