From: ake.ragnar.dahlgren@gmail.com
Subject: Re: Ada and string literals
Date: Thu, 31 Jan 2013 01:20:41 -0800 (PST)
Date: 2013-01-31T01:20:41-08:00 [thread overview]
Message-ID: <5395c5ee-6731-4a0b-80c2-63b31cc21add@googlegroups.com> (raw)
In-Reply-To: <86boc63n5d.fsf@gaheris.avalon.lan>
On Wednesday, January 30, 2013 12:50:38 PM UTC+1, Mart van de Wege wrote:
> 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; More importantly, I cannot see why you would want an access to a string literal. Just use the string literal as a normal 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 Studio). This is code taken from the procedure GPS.Main:
subtype String_Access is GNAT.Strings.String_Access;
Home : String_Access;
Home_Dir : Virtual_File;
Project_Name : Virtual_File := No_File;
Prefix : String_Access;
Prefix_Dir : Virtual_File;
GPS_Home_Dir : Virtual_File;
Batch_File : String_Access;
Batch_Script : String_Access;
Tools_Host : String_Access;
Target : String_Access;
Protocol : String_Access;
Debugger_Name : String_Access;
Startup_Dir : String_Access;
About_Contents : String_Access;
The string access type was chosen over the string type for handling strings. Maybe to avoid setting a maximum string length? Performance reasons? Anyways, I think the authors of the GPS are able to give a good motivation of when one prefers the string access type over the ordinary string type.
Best regards,
Åke Ragnar Dahlgren
next prev parent reply other threads:[~2013-01-31 9: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 [this message]
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
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