* Naive question @ 1998-08-22 0:00 Maxim Senin 1998-08-23 0:00 ` John Herro ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: Maxim Senin @ 1998-08-22 0:00 UTC (permalink / raw) How to assign value to integer like in C: int i = 'm';? I tried i : Integer := Integer'Value ("m"); but it throws CONSTRAINT_ERROR. Thanks ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Naive question 1998-08-22 0:00 Naive question Maxim Senin @ 1998-08-23 0:00 ` John Herro 1998-08-27 0:00 ` Steve Doiel 1998-09-19 0:00 ` Tom Moran 2 siblings, 0 replies; 4+ messages in thread From: John Herro @ 1998-08-23 0:00 UTC (permalink / raw) Maxim Senin <maks@tech.swh.lv> points out that i : Integer := Integer'Value ("m"); raises Constraint_Error. Right. Instead, use I : Integer := Character'Pos('m'); Note the single tic marks around the m. Since 'm' is of type Character, Character'Pos converts from Character to an integer type. To go the other way, Character'Val(109) converts from an integer type to Character. The attribute 'Value converts from type *String*, and 'Image converts *to* String. Thus Integer'Value("123") is 123, and Integer'Image(123) is " 123". HTH. - John Herro You can download a shareware Ada Tutor program at http://members.aol.com/AdaTutor ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Naive question 1998-08-22 0:00 Naive question Maxim Senin 1998-08-23 0:00 ` John Herro @ 1998-08-27 0:00 ` Steve Doiel 1998-09-19 0:00 ` Tom Moran 2 siblings, 0 replies; 4+ messages in thread From: Steve Doiel @ 1998-08-27 0:00 UTC (permalink / raw) Use: i : Integer := Character'Pos( 'M' ); to get the ordinal value of a character. i : Integer := Integer'Value ("12"); Assignes the value of 12 to i. SteveD Maxim Senin wrote in message <35DF1997.3CB29CD6@tech.swh.lv>... >How to assign value to integer like in C: int i = 'm';? > >I tried > i : Integer := Integer'Value ("m"); >but it throws CONSTRAINT_ERROR. > >Thanks > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Naive question 1998-08-22 0:00 Naive question Maxim Senin 1998-08-23 0:00 ` John Herro 1998-08-27 0:00 ` Steve Doiel @ 1998-09-19 0:00 ` Tom Moran 2 siblings, 0 replies; 4+ messages in thread From: Tom Moran @ 1998-09-19 0:00 UTC (permalink / raw) >How to assign value to integer like in C: int i = 'm';? Do you mean i : integer := Character'Pos('m'); Or is there some other thing you might mean by the integer value of a letter of the alphabet? ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1998-09-19 0:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1998-08-22 0:00 Naive question Maxim Senin 1998-08-23 0:00 ` John Herro 1998-08-27 0:00 ` Steve Doiel 1998-09-19 0:00 ` Tom Moran
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox