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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1db5f5538715d789 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: integer'image Date: 2000/04/17 Message-ID: #1/1 X-Deja-AN: 612356277 References: <29IK4.5459$sB3.3596@news.indigo.ie> X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 955999266 206.170.2.81 (Mon, 17 Apr 2000 12:21:06 PDT) Organization: SBC Internet Services NNTP-Posting-Date: Mon, 17 Apr 2000 12:21:06 PDT Newsgroups: comp.lang.ada Date: 2000-04-17T00:00:00+00:00 List-Id: > integer_string:string(1..2); > integer_string:=integer'image(x); > everything is fine until x=10. This raises a constraint error which I > interpret to be a problem with mismatched string lenghts. If I increase > integer_string lenght a constraint error is raised on the first iteration. > > I'm sure that it is a standard application to convert integers to their > string images but I can't figure what I'm missing here. Integer'image(1) is " 1", a two character string. Integer'image(10) is " 10", a three character string. Integer'image(100) is " 100", a four character string. so declaing the string to be 2 characters long limits you to integer'image of -9 .. 9. The usual idiom is to do declare integer_string : string :=integer'image(x); begin ... end; which will make integer_string just exactly the right length, not too short and not too long. If you need integer_string to be available more globally, try integer_string : string(1 .. 4) := (others=> ' '); -- max " 999" ... declare this_integer_string : constant string := integer'image(x); begin integer_string := (this_integer_string'length+1 .. integer_string'length => ' ') & this_integer_string; end; Alternatively, just use Ada.Text_IO.Integer_IO.Put