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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dc1fff2721602dfa X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII X-Received: by 10.224.110.68 with SMTP id m4mr4112863qap.2.1359624041505; Thu, 31 Jan 2013 01:20:41 -0800 (PST) X-Received: by 10.49.84.167 with SMTP id a7mr759867qez.11.1359624041274; Thu, 31 Jan 2013 01:20:41 -0800 (PST) Path: k2ni3907qap.0!nntp.google.com!p13no7321390qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 31 Jan 2013 01:20:41 -0800 (PST) In-Reply-To: <86boc63n5d.fsf@gaheris.avalon.lan> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=136.163.203.9; posting-account=l8k8IwoAAADeDydswOzwNzmn10qOk9gt NNTP-Posting-Host: 136.163.203.9 References: <4978d638-a04b-4561-85e9-cf6620265af2@googlegroups.com> <86boc63n5d.fsf@gaheris.avalon.lan> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5395c5ee-6731-4a0b-80c2-63b31cc21add@googlegroups.com> Subject: Re: Ada and string literals From: ake.ragnar.dahlgren@gmail.com Injection-Date: Thu, 31 Jan 2013 09:20:41 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2013-01-31T01:20:41-08:00 List-Id: On Wednesday, January 30, 2013 12:50:38 PM UTC+1, Mart van de Wege wrote: > 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 ? >> >> a= bc : access string :=3D "LITERAL"; -- error. > > Because, unlike C, Ada doe= s not confuse arrays with pointers. > > This is the closest Ada equivalent:= > > Literal : aliased constant String :=3D "LITERAL"; > abc : access const= ant String :=3D Literal'Access; More importantly, I cannot see why you woul= d want an access to a string literal. Just use the string literal as a norm= al parameter, and let the compiler worry about how to handle that. Mart -- = "We will need a longer wall when the revolution comes." --- AJS, quoting an= uncertain source. The other day I was looking at the Ada code for the GPS (GNAT Programming S= tudio). This is code taken from the procedure GPS.Main: subtype String_Access is GNAT.Strings.String_Access; Home : String_Access; Home_Dir : Virtual_File;=20 Project_Name : Virtual_File :=3D No_File;=20 Prefix : String_Access; Prefix_Dir : Virtual_File;=20 GPS_Home_Dir : Virtual_File;=20 Batch_File : String_Access;=20 Batch_Script : String_Access;=20 Tools_Host : String_Access;=20 Target : String_Access;=20 Protocol : String_Access;=20 Debugger_Name : String_Access;=20 Startup_Dir : String_Access;=20 About_Contents : String_Access; =20 The string access type was chosen over the string type for handling strings= . Maybe to avoid setting a maximum string length? Performance reasons? Anyw= ays, I think the authors of the GPS are able to give a good motivation of w= hen one prefers the string access type over the ordinary string type. Best regards, =C5ke Ragnar Dahlgren