From: NiGHTS <nights@unku.us>
Subject: Re: Assembling Complex Strings Containing Carriage Returns Prior to Using Ada.Text_IO.Put?
Date: Wed, 22 Oct 2014 11:01:42 -0700 (PDT)
Date: 2014-10-22T11:01:42-07:00 [thread overview]
Message-ID: <eaa49258-a9e9-4541-86ad-a321426a5533@googlegroups.com> (raw)
In-Reply-To: <1c18d4c3-aa53-4547-85c9-55477cde7364@googlegroups.com>
On Wednesday, October 22, 2014 1:44:30 PM UTC-4, Adam Beneschan wrote:
> On Tuesday, October 21, 2014 10:57:39 PM UTC-7, NiGHTS wrote:
>
> > I am converting some code from C to Ada which involves building a complex string containing '\n' characters which would eventually be displayed on the standard output console using the printf() function.
>
>
>
> > I tried to copy the same strategy of building the string in Ada like this:
>
>
>
> > Complex_String : Ada.Strings.Unbounded.Unbounded_String;
>
> >
>
> > EOL : String := ASCII.CR'Img;
>
>
>
> As others have pointed out, 'Img is a GNAT-defined attribute; it depends on the Ada-defined attribute 'Image. 'Image is not intended to convert a Character to a one-character String. If you say
>
>
>
> C : Character := 'x';
>
> S : String := Character'Image (C);
>
>
>
> S will have length 3 and will be "'x'".
>
>
>
> Character is an enumeration type in Ada, although it's somewhat special. But the rules for 'Image (and its converse, 'Value) are the same as for other enumeration types: they give you (or expect) a string that looks like what the enumeration value would look like in the enumeration declaration. For example, with this enumeration type:
>
>
>
> type Color is (RED, GREEN, BLUE);
>
>
>
> the 'Image attribute will produce "RED", "GREEN", or "BLUE". (It's always upper-case for identifiers.) And for an enumeration type that has character literals mixed in:
>
>
>
> type Whatsit is (This, That, '?');
>
>
>
> 'Image will produce "THIS", "THAT", or "'?'". (What makes Character special is that if you give it a non-printable character, there are special rules for what 'Image returns; in your case it returned "CR".)
>
>
>
> -- Adam
This is clear to me now. I will try to avoid 'Img now that I know its GNAT-specific, or at the very least move it to a file specifically named to be compiled only in gnat. Thank you for your help.
next prev parent reply other threads:[~2014-10-22 18:01 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 5:57 Assembling Complex Strings Containing Carriage Returns Prior to Using Ada.Text_IO.Put? NiGHTS
2014-10-22 6:20 ` mockturtle
2014-10-22 6:28 ` Ludovic Brenta
2014-10-22 8:12 ` mockturtle
2014-10-22 14:36 ` Maciej Sobczak
2014-10-22 14:55 ` Dmitry A. Kazakov
2014-10-24 1:35 ` Keith Thompson
2014-10-22 16:01 ` Shark8
2014-10-22 16:50 ` Jeffrey Carter
2014-10-22 18:59 ` Simon Wright
2014-10-22 23:45 ` Dennis Lee Bieber
2014-10-23 11:38 ` G.B.
2014-10-23 16:22 ` Shark8
2014-10-22 17:32 ` Adam Beneschan
2014-10-22 17:55 ` NiGHTS
2014-10-22 17:16 ` NiGHTS
2014-10-22 6:25 ` Jeffrey Carter
2014-10-22 17:39 ` NiGHTS
2014-10-22 11:16 ` Björn Lundin
2014-10-22 17:44 ` Adam Beneschan
2014-10-22 17:47 ` Adam Beneschan
2014-10-22 18:01 ` NiGHTS [this message]
2014-10-22 22:34 ` Shark8
2014-10-22 23:32 ` Adam Beneschan
2014-10-24 2:45 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox