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,dc1fff2721602dfa X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.66.84.164 with SMTP id a4mr652709paz.26.1359562818795; Wed, 30 Jan 2013 08:20:18 -0800 (PST) Path: s9ni26125pbb.0!nntp.google.com!news.glorb.com!xmission!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada and string literals Date: Wed, 30 Jan 2013 11:20:17 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4978d638-a04b-4561-85e9-cf6620265af2@googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1359562817 2502 192.74.137.71 (30 Jan 2013 16:20:17 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 30 Jan 2013 16:20:17 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:PMVaGb3wvRbP74MxruioxkO1LC0= Content-Type: text/plain; charset=us-ascii Date: 2013-01-30T11:20:17-05:00 List-Id: Niklas Holsti 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