comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Conversions
Date: Mon, 26 Oct 2009 13:19:10 -0700 (PDT)
Date: 2009-10-26T13:19:10-07:00	[thread overview]
Message-ID: <0654c44b-6db9-4304-b3c0-5cd7b870eb4c@v15g2000prn.googlegroups.com> (raw)
In-Reply-To: 1256585268.3272.14.camel@HERMES

On Oct 26, 12:27 pm, Bruno <brunomend...@gmail.com> wrote:
> Hi all,
>
> I have a little problem with a function that "convert" a date, that is a
> record type, into a string. To do this I'm using "image" attribute how
> can you see in the following code
>
> http://paste.ideaslabs.com/show/5KEJUGcDF
>
> but when run the program and the function is executed a get an
> "constraint error". The compiler show me a message that say that the
> size is too long but I don't know what to do.

'Image returns a string whose first character is a space if the
argument is not negative.  So if N = 12, then Integer'Image(N) = "
12"---i.e. 3 characters.  That won't fit in the two-character slice
you're trying to put it in, so you get a Constraint_Error.

But just getting rid of the space doesn't work either.  If N = 1, then
Integer'Image(N) = " 1", and if you were able to trim off the space,
the result would be "1", and you'd still get a Constraint_Error.  When
you assign a slice like this, the left and right sides must be the
same length.

There are a number of ways to do what you want, but I'd suggest
looking at the Ada.Strings.Fixed package, especially the Move, Trim,
and Tail routines.

Hope this helps,

                                    -- Adam




  parent reply	other threads:[~2009-10-26 20:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 12:40 Ada.Directories.Base_Name and dot files 
2009-10-07 14:46 ` Yannick Duchêne Hibou57
2009-10-07 17:06   ` 
2009-10-07 14:52 ` Adam Beneschan
2009-10-07 17:06   ` 
2009-10-07 15:10 ` Adam Beneschan
2009-10-07 15:37   ` Yannick Duchêne Hibou57
2009-10-11  2:39     ` Randy Brukardt
2009-10-07 20:11   ` 
2009-10-08  9:39 ` Stephen Leake
2009-10-08  9:58   ` 
2009-10-26 19:26     ` Type casting Bruno
2009-10-26 20:02       ` Jeffrey R. Carter
2009-10-26 20:09       ` Adam Beneschan
2009-10-26 19:27     ` Conversions Bruno
2009-10-26 20:09       ` Conversions Jeffrey R. Carter
2009-10-26 20:19       ` Adam Beneschan [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-03-16  0:00 Conversions Karlene Johnson
2000-03-16  0:00 ` Conversions Marin D. Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox