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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,CP1252 X-Google-Thread: 103376,38c827f7e800d317 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-05 20:53:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail Message-ID: <3F079D10.2060709@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: conversion References: <3EFCC18B.4040904@attbi.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc03 1057463583 24.62.164.137 (Sun, 06 Jul 2003 03:53:03 GMT) NNTP-Posting-Date: Sun, 06 Jul 2003 03:53:03 GMT Organization: AT&T Broadband Date: Sun, 06 Jul 2003 03:53:03 GMT Xref: archiver1.google.com comp.lang.ada:40086 Date: 2003-07-06T03:53:03+00:00 List-Id: Alexander Kopilovitch wrote: > /* C/C++ example */ > > char *Titles[] = { > "Quizionary", > "Nose To Nose", > "Myself", > "General Dissent", > "Veteran's Opinion", > "Corporate Science Weekly", > "Truth, Wealth, Health", > "Bribery Times" > }; > > > { Object Pascal example } > > const > Dishes : array [1..4] of String = ( > 'black pudding', > 'crab soup', > 'steak & kidney pie', > 'lemon tart' > ); Two examples. One without any Ada support packages, and one that uses Ada.Strings.Bounded. Personally I think that during standarization, to much was added in, and as a result, Ada.Strings.Bounded is harder to use than it should be. But of course, you can roll your own, the way you had to in Ada 83. But notice two major differences between the Ada way, and the C and Pascal way. The Ada solutions are built around standard Ada features, not special case features, and the Ada solution allows for non-constant arrays, in fact the individual elements can change in length. (Yes, I know that in the C++ case you can assign other pointers, but the original values can't be modified as such.) procedure Varying is -- an example of how to create ragged arrays in Ada. subtype Lim_Int is Integer range 0..30; type Inner(L: Lim_Int := 0) is record S: String(1..L); end record; type Wrapper is record I: Inner; end record; type Ragged_Array is array (Integer range <>) of Wrapper; function "+" (S: in String) return Wrapper is begin return (I =>(S'Length, S)); end "+"; function "+" (W: in Wrapper) return String is begin return W.I.S; end "+"; Dishes: Ragged_Array := (+"black pudding", +"crab soup", +"steak & kidney pie", +"lemon tart"); Titles: Ragged_Array := (+"Quizionary", +"Nose To Nose", +"Myself", +"General Dissent", +"Veteran's Opinion", +"Corporate Science Weekly", +"Truth, Wealth, Health", +"Bribery Times"); begin null; end Varying; with Ada.Strings.Bounded; procedure Varying2 is -- an example of how to use Ada.Strings.Bounded. package Bounded_Str is new Ada.Strings.Bounded.Generic_Bounded_Length(30); subtype Bounded_String is Bounded_Str.Bounded_String; function "+" (S: in String) return Bounded_String is begin return Bounded_Str.To_Bounded_String(S, Ada.Strings.Error); end "+"; function "+" (B: in Bounded_String) return String renames Bounded_Str.To_String; type Ragged_Array is array (Integer range <>) of Bounded_String; Dishes: Ragged_Array := (+"black pudding", +"crab soup", +"steak & kidney pie", +"lemon tart"); Titles: Ragged_Array := (+"Quizionary", +"Nose To Nose", +"Myself", +"General Dissent", +"Veteran's Opinion", +"Corporate Science Weekly", +"Truth, Wealth, Health", +"Bribery Times"); begin null; end Varying2; -- Robert I. Eachus �In an ally, considerations of house, clan, planet, race are insignificant beside two prime questions, which are: 1. Can he shoot? 2. Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and Steve Miller.